wordpress代码精简和优化

1.css和JS压缩 可以使用yuicompressor 在线压缩 压缩时其他选择不勾

2.head 代码精简 去除不需要的代码功能 

主题functions.php里面

/**
* Disable Our Feed Urls
*/
function disable_our_feeds() {
wp_die( __('目前不提供 RSS 功能,请前往我们的<a href="'. get_bloginfo('url') .'">首页</a>。') );
}

add_action('do_feed', 'disable_our_feeds', 1);
add_action('do_feed_rdf', 'disable_our_feeds', 1);
add_action('do_feed_rss', 'disable_our_feeds', 1);
add_action('do_feed_rss2', 'disable_our_feeds', 1);
add_action('do_feed_atom', 'disable_our_feeds', 1);
remove_action('wp_head', 'feed_links_extra', 3);//清除feed信息
remove_action('wp_head', 'feed_links', 2);//清除feed信息

remove_action('wp_head', 'rsd_link');//清除离线编辑器接口
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head',10,0);
remove_action('wp_head', 'wp_generator');//去除版本信息
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head',10,0);//清除前后文信息

还有就是include里面的default-filters.php 优先

//Actions 里面注视 或者去除

// Actions
add_action( 'wp_head',             'wp_enqueue_scripts',              1     );
//add_action( 'wp_head',             'feed_links',                      2     );
//add_action( 'wp_head',             'feed_links_extra',                3     );
//add_action( 'wp_head',             'rsd_link'                               );
//add_action( 'wp_head',             'wlwmanifest_link'                       );
add_action( 'wp_head',             'adjacent_posts_rel_link_wp_head', 10, 0 );
add_action( 'wp_head',             'locale_stylesheet'                      );
add_action( 'publish_future_post', 'check_and_publish_future_post',   10, 1 );
add_action( 'wp_head',             'noindex',                          1    );
add_action( 'wp_head',             'wp_print_styles',                  8    );
add_action( 'wp_head',             'wp_print_head_scripts',            9    );
//add_action( 'wp_head',             'wp_generator'                           );
add_action( 'wp_head',             'rel_canonical'                          );
add_action( 'wp_footer',           'wp_print_footer_scripts',         20    );
//add_action( 'wp_head',             'wp_shortlink_wp_head',            10, 0 );
add_action( 'template_redirect',   'wp_shortlink_header',             11, 0 );
add_action( 'wp_print_footer_scripts', '_wp_footer_scripts'                 );
add_action( 'init',                'check_theme_switched',            99    );
add_action( 'after_switch_theme',  '_wp_sidebars_changed'                   );

// Feed Generator Tags
foreach ( array('commentsrss2_head','rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) {
	add_action( $action, 'the_generator' );

3.去除页面里面的评论 RSS 文章 RSS wordpress.org

include下面的default-widgets.php  查找Meta widget class

删除或者注释

<li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
 <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
 <li><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>"><?php
 /* translators: meta widget link text */
 _e( 'WordPress.org' );
 ?></a></li>

OK 清理下来清爽多了 

wordpress代码精简和优化》有一个想法

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据