Home > Net >  Any way to get two functions to work on the same request?
Any way to get two functions to work on the same request?

Time:02-01

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.

CodePudding user response:

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. 

CodePudding user response:

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;
});
  • Related