skip to Main Content

i’m trying to hide the title tag of the head of my template. I’m using this code:

add_action( 'template_redirect', 'remove_wpseo' );
function remove_wpseo() {
    if ( is_single ( 123456 ) ) {
        global $wpseo_front;

        if ( defined( $wpseo_front ) ) {
            remove_action( 'wp_head', array ($wpseo_front, 'head' ), 1 );
        } else {
            $wp_thing = WPSEO_Frontend::get_instance();
            remove_action( 'wp_head', array( $wp_thing, 'head' ), 1 );
        }
    }
}

But it does not work.

3

Answers


  1. It will work. please add the page id in the condition like below:-

    Note:- This is for post detail page if ( is_single ( 123456 ) )

    Please add below code in function.php and don’t forget to change page id with specific page from which you want to remove.

    if ( get_the_ID()==96 )

    add_action( 'template_redirect', 'remove_wpseo' );
    function remove_wpseo() {
        if ( get_the_ID()==96 ) {
            global $wpseo_front;
    
            if ( defined( $wpseo_front ) ) {
                remove_action( 'wp_head', array ($wpseo_front, 'head' ), 1 );
            } else {
                $wp_thing = WPSEO_Frontend::get_instance();
                remove_action( 'wp_head', array( $wp_thing, 'head' ), 1 );
            }
        }
    }
    
    Login or Signup to reply.
  2. You may try to visit the link here

    Moreover, Try Yoast solution here

    Hope this helps!

    Login or Signup to reply.
  3. As of Yoast SEO 14.0, disable all Yoast output. Warning, the tags are removed. Taken from Yoast docs:

    function intervik_theme_wpseo_remove(){
        if(function_exists('YoastSEO')){
            $front_end = YoastSEO()->classes->get( YoastWPSEOIntegrationsFront_End_Integration::class );
            if ( is_single ( 123456 ) ) remove_action('wpseo_head', [ $front_end, 'present_head' ], -9999 );
        }
    }
    add_action('template_redirect', 'intervik_theme_wpseo_remove');
    

    However, you might take a look at the new API, removing Title only:

    function intervik_wpseo_frontend_presenters($presenters){
        if ( !is_single ( 123456 ) ) return $presenters;
        /* REMOVE ONE exactly presenters */
        if(($key = array_search('YoastWPSEOPresentersTwitterTitle_Presenter', $presenters)) !== false){
            unset($presenters[$key]);
        }
        return $presenters;
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    Removing all default social_meta related tags:

    function intervik_wpseo_frontend_presenters($presenters){
    
        /* return all WITHOUT Open_Graph and Twitter presenters */
        
        if($matches = preg_grep('/Open_Graph|Twitter/', $presenters)) return array_diff($presenters, $matches);
            else return $presenters;
    
    }
    add_filter('wpseo_frontend_presenter_classes', 'intervik_wpseo_frontend_presenters', 10, 1);
    

    Where presenters are for example (dump):

    array(27) {
      [0]=>
      string(39) "YoastWPSEOPresentersTitle_Presenter"
      [1]=>
      string(50) "YoastWPSEOPresentersMeta_Description_Presenter"
      [2]=>
      string(40) "YoastWPSEOPresentersRobots_Presenter"
      [3]=>
      string(43) "YoastWPSEOPresentersGooglebot_Presenter"
      [4]=>
      string(41) "YoastWPSEOPresentersBingbot_Presenter"
      [5]=>
      string(43) "YoastWPSEOPresentersCanonical_Presenter"
      [6]=>
      string(42) "YoastWPSEOPresentersRel_Prev_Presenter"
      [7]=>
      string(42) "YoastWPSEOPresentersRel_Next_Presenter"
      [8]=>
      string(51) "YoastWPSEOPresentersOpen_GraphLocale_Presenter"
      [9]=>
      string(49) "YoastWPSEOPresentersOpen_GraphType_Presenter"
      [10]=>
      string(50) "YoastWPSEOPresentersOpen_GraphTitle_Presenter"
      [11]=>
      string(56) "YoastWPSEOPresentersOpen_GraphDescription_Presenter"
      [12]=>
      string(48) "YoastWPSEOPresentersOpen_GraphUrl_Presenter"
      [13]=>
      string(54) "YoastWPSEOPresentersOpen_GraphSite_Name_Presenter"
      [14]=>
      string(62) "YoastWPSEOPresentersOpen_GraphArticle_Publisher_Presenter"
      [15]=>
      string(59) "YoastWPSEOPresentersOpen_GraphArticle_Author_Presenter"
      [16]=>
      string(67) "YoastWPSEOPresentersOpen_GraphArticle_Published_Time_Presenter"
      [17]=>
      string(66) "YoastWPSEOPresentersOpen_GraphArticle_Modified_Time_Presenter"
      [18]=>
      string(50) "YoastWPSEOPresentersOpen_GraphImage_Presenter"
      [19]=>
      string(54) "YoastWPSEOPresentersOpen_GraphFB_App_ID_Presenter"
      [20]=>
      string(46) "YoastWPSEOPresentersTwitterCard_Presenter"
      [21]=>
      string(47) "YoastWPSEOPresentersTwitterTitle_Presenter"
      [22]=>
      string(53) "YoastWPSEOPresentersTwitterDescription_Presenter"
      [23]=>
      string(47) "YoastWPSEOPresentersTwitterImage_Presenter"
      [24]=>
      string(49) "YoastWPSEOPresentersTwitterCreator_Presenter"
      [25]=>
      string(46) "YoastWPSEOPresentersTwitterSite_Presenter"
      [26]=>
      string(40) "YoastWPSEOPresentersSchema_Presenter"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search