skip to Main Content

I’m trying to remove the Yoast schema on posts and pages in my functions.php. But, one will work but together they won’t. Any way to get this to work together?

Here’s what I have tried so far:

//Remove All Schema on post
add_filter( 'wpseo_json_ld_output', 'yoast_seo_json_remove_partial_post' );

function yoast_seo_json_remove_partial_post() {
  if ( is_single ( [ 2544, 2743  ] ) ) {
    return false;
  }
}

//Remove Schema on Page
add_filter( 'wpseo_json_ld_output', 'yoast_seo_json_remove_partial_page' );

function yoast_seo_json_remove_partial_page () {

  if ( is_page ( [ 15,  ] ) ) {
    return false;
  }
}

I need to remove them from any page I want if possible. Thanks for any help with this.

2

Answers


  1. You can just use OR operator for conditional

    add_filter( 'wpseo_json_ld_output', function( $default ) {
    
        if ( is_single ( [ 2544, 2743  ] ) || is_page ( 15 ) )
            return false;
    
        return $default;
    });
    
    Login or Signup to reply.
  2. Please remove the , from the code below. It might terminate the code

     if ( is_page ( [ 15,  ] ) ) {
        return false;
      }
    }
    

    Alternatively, instead of using two functions, please create one and combine both conditions using the logical OR operator. 

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search