二次开发笔记

最新wordpress php wp_head()函数精简,删除php wp_head()中的title标签

【笔记】因为SEO需要对WP主题进行二开,其中发现新版WP的<?php wp_head(); ?>函数调用了title。这样就很坑爹了 出现两title!所以我需要:

①精简<?php wp_head(); ?>函数 (版本信息、feed等等

②去除<?php wp_head(); ?>函数中的title

wp更新以后我是没找到wp-includes 文件夹下的 default-filters.php 文件,所以只能自己利用functions.php来实现,

将下面代码放到主题的functions.php(认真看最后一行)

//精简<?php wp_head(); ?>
remove_action( 'wp_head', 'wp_generator' );//WordPress版本信息。
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );//最后文章的url
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );//最前文章的url
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );//上下
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );//上下文章的url
remove_action( 'wp_head', 'feed_links_extra', 3 );//去除评论feed
remove_action( 'wp_head', 'feed_links', 2 );//去除文章的feed
remove_action( 'wp_head', 'rsd_link' );//针对Blog的离线编辑器开放接口所使用
remove_action( 'wp_head', 'wlwmanifest_link' );//如上
remove_action( 'wp_head', 'index_rel_link' );//当前页面的url
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );//短地址
remove_action( 'wp_head', 'rel_canonical');
wp_deregister_script('l10n');
remove_filter( 'the_content', 'wptexturize');//禁用半角符号自动转换为全角
remove_action( 'wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));  
//删除wp_head()中的title标签
remove_action( 'wp_head', '_wp_render_title_tag', 1 );

OK 搞定!

2 thoughts on “最新wordpress php wp_head()函数精简,删除php wp_head()中的title标签

Comments are closed.