Mub*_*har 4 wordpress wordpress-plugin
我在我的博客上安装了wordpress SEO Yoast插件.我想避免使用SEO Yoast为我的博客生成标题.有什么方法可以删除SEO Yoast插件应用的过滤器wp_title()吗?我想使用页面标题作为SEO标题.
add_filter( 'wp_title', 'te_before_filter_wp_title' );
function te_before_filter_wp_title( $title ) {
echo $title;
//exit;
return $title;
}
add_filter( 'wp_title', 'te_after_filter_wp_title' ,9999);
function te_after_filter_wp_title( $title ) {
echo $title;
//exit;
return $title;
}
Run Code Online (Sandbox Code Playgroud)
我已经编写了这段代码来测试标题.而在标题te_before_filter_wp_title和te_after_filter_wp_title是不同的.所以它被SEO YOAST插件修改.
对于旧版本的WPSEO(v1~2),您可以使用以下代码删除它应用的过滤器:
add_action( 'init', function() {
global $wpseo_front;
remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 );
}, 20 );
Run Code Online (Sandbox Code Playgroud)
对于较新版本的WPSEO(~3 +)和WordPress(4.4+),可以使用以下代码删除过滤器:
add_action( 'init', function () {
$wpseo_front = WPSEO_Frontend::get_instance();
remove_filter( 'pre_get_document_title', array( $wpseo_front, 'title' ), 15 );
remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 );
} );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4288 次 |
| 最近记录: |