Disable Schema on Selected Pages

#160815
  • Resolved Frances Bernard
    Rank Math free

    Hi,

    Please could you provide me a with a code snippet that I can put in functions.php.

    I would like to keep rich snippets on all pages BUT disable Schema on selected pages in the head on my site.

    Many thanks.

    🙂

    Frances

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    You can use and modify this filter by adding at the bottom of your theme’s functions.php file:

    
    /**
     * Code to remove json+ld data
     * 
     */
    add_action( 'rank_math/head', function() {
    	global $post;
    
    	if( $post->ID == 1) {
    		global $wp_filter;
    		if ( isset( $wp_filter["rank_math/json_ld"] ) ) {
    			unset( $wp_filter["rank_math/json_ld"] );
    		}
    	}
    });
    

    Then replace the ID of the post with the one from the page you want to remove the schema. Here’s how you find the post/page ID inside WordPress: https://mythemeshop.com/blog/how-to-find-post-category-tag-comments-or-user-id-in-wordpress/

    I hope that helps. Thank you, and looking forward to your update.

    Thank you Reinelle – much appreciated.

    Please advise how I configure this line to cover more than one page

    if( $post->ID == 1)

    Do I put commas between page numbers – if( $post->ID == 1,2,3,4)

    Or brackets or inverted commas?

    Many thanks.

    Frances

    Hi there,

    You want to add more expressions inside that one big brackets we mean something like this:

    if($post->ID == 1 || $post->ID == 2 || $post->ID == 3){
    //if any of the above match this code runs
    }

    the think of || as an or

    Try that.
    Cheers.

    Thank you Michael & Reinelle,

    I am going to purchase a license for one of my other sites.

    I really appreciate your help.

    You guys are great!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Disable Schema on Selected Pages’ is closed to new replies.