简化或优化WordPress主题功能
我需要一些建议来简化甚至优化以下 WordPress 主题功能。
第一个删除了一些我不需要的主题功能和默认 WordPress 标题内容。第二个添加了一些 Javascript 和 CSS 文件,但前提是用户不是管理员。
<?php
add_action('after_setup_theme', 'remove_theme_features', 11 );
function remove_theme_features() {
$GLOBALS['custom_background'] = 'kill_theme_features';
$GLOBALS['custom_image_header'] = 'kill_theme_features';
remove_theme_support('post-formats');
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
}
class kill_theme_features {
function init() { return false; }
}
if ( !is_admin() ) {
add_action('init', 'hno_init_js');
function hno_init_js() {
wp_enqueue_script('carousel', get_bloginfo('stylesheet_directory') . '/js/carousel/jquery.jcarousel.min.js', array('jquery'), '1', true);
wp_enqueue_script('history', get_bloginfo('stylesheet_directory') . '/js/carousel/jquery.history.min.js', array('jquery'), '1', true);
wp_enqueue_script('galleria', get_bloginfo('stylesheet_directory') . '/js/carousel/jquery.galleria.min.js', array('jquery'), '1', true);
wp_enqueue_script('fancybox_js', get_bloginfo('stylesheet_directory') . '/js/fancybox/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1', true);
wp_enqueue_script('hno', get_bloginfo('stylesheet_directory') . '/js/hno.js', array('jquery'), '1', true);
}
wp_enqueue_style('carousel_css', get_bloginfo('stylesheet_directory') . '/js/carousel/tango/skin.css', array() , false , 'screen' );
wp_enqueue_style('fancybox_css', get_bloginfo('stylesheet_directory') . '/js/fancybox/jquery.fancybox-1.3.4.css', array() , false , 'screen' );
}
?>
非常感谢!
问候史蒂夫
i need some suggestions to simplifying or even optimizing the following WordPress Theme Functions.
The first one removes some Theme features and Default Wordpress Header stuff i don't nedd. The Second adds some Javascript and CSS Files, but only if the user are not an Admin.
<?php
add_action('after_setup_theme', 'remove_theme_features', 11 );
function remove_theme_features() {
$GLOBALS['custom_background'] = 'kill_theme_features';
$GLOBALS['custom_image_header'] = 'kill_theme_features';
remove_theme_support('post-formats');
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
}
class kill_theme_features {
function init() { return false; }
}
if ( !is_admin() ) {
add_action('init', 'hno_init_js');
function hno_init_js() {
wp_enqueue_script('carousel', get_bloginfo('stylesheet_directory') . '/js/carousel/jquery.jcarousel.min.js', array('jquery'), '1', true);
wp_enqueue_script('history', get_bloginfo('stylesheet_directory') . '/js/carousel/jquery.history.min.js', array('jquery'), '1', true);
wp_enqueue_script('galleria', get_bloginfo('stylesheet_directory') . '/js/carousel/jquery.galleria.min.js', array('jquery'), '1', true);
wp_enqueue_script('fancybox_js', get_bloginfo('stylesheet_directory') . '/js/fancybox/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1', true);
wp_enqueue_script('hno', get_bloginfo('stylesheet_directory') . '/js/hno.js', array('jquery'), '1', true);
}
wp_enqueue_style('carousel_css', get_bloginfo('stylesheet_directory') . '/js/carousel/tango/skin.css', array() , false , 'screen' );
wp_enqueue_style('fancybox_css', get_bloginfo('stylesheet_directory') . '/js/fancybox/jquery.fancybox-1.3.4.css', array() , false , 'screen' );
}
?>
Thank you very much!
Regards Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
头部清洁器是我用来为我完成这一切的插件!
我只是以标准方式将所有 js 和 css 放入头部,然后使用头部清理器的功能,直到获得漂亮的、精简的代码。
http://wordpress.org/extend/plugins/head-cleaner/
不隶属顺便说一句,无论如何!
Head cleaner is the plugin i use to do all this for me!
I just drop in all my js and css into the head in the standard way, then play around with the functions of head cleaner until I have nice, streamlined code.
http://wordpress.org/extend/plugins/head-cleaner/
not affiliated in any way btw!