【问题标题】:How to remove SEO Yoast page title filter?如何删除 SEO Yoast 页面标题过滤器?
【发布时间】:2014-03-28 22:18:00
【问题描述】:

我已经在我的博客上安装了 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;

}

我写了这段代码来测试标题。 te_before_filter_wp_titlete_after_filter_wp_title 中的标题不同。所以它正在被SEO YOAST插件修改。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    使用旧版本的 WPSEO (v1~2),您可以使用以下代码删除 the filter it applies

    add_action( 'init', function() {
        global $wpseo_front;
        remove_filter( 'wp_title', array( $wpseo_front, 'title' ), 15 );
    }, 20 );
    

    使用较新版本的 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 );
    } );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      相关资源
      最近更新 更多