Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove SEO Yoast page title filter?

Tags:

wordpress

I have installed the wordpress SEO Yoast plugin on my blog. I want to avoid using SEO Yoast generated title for my blog. Is there any way I can remove filter that are being applied by SEO Yoast plugin for wp_title()? I want to use the page title as SEO title.

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;

}

I have write this code to test the title. And title in te_before_filter_wp_title and in te_after_filter_wp_title is different. So it is being modified by SEO YOAST plugin.

like image 258
Mubbashar Avatar asked Mar 20 '23 10:03

Mubbashar


1 Answers

With older versions of WPSEO (v1~2), you can remove the filter it applies with the following code:

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

With newer versions of WPSEO (~3+) and WordPress (4.4+), the filter(s) can be removed with the following code:

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 );
} );
like image 92
brasofilo Avatar answered Mar 23 '23 00:03

brasofilo