Disable Schema on One Page

#159032
  • Resolved Matt Jackson
    Rank Math free

    Hi, can you tell me how to remove the schema.org Rank Math generates on a single page?

    I’ve tested a “Remove Schema” plugin for it, but it doesn’t work with Rank Math for some reason.
    Thanks!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Anas
    Rank Math business

    Hello,

    Thank you for contacting Rank Math, and sorry for any inconvenience caused.

    Rank Math assigns the default schema to all pages/posts if you have selected the schema type in Rank Math > Titles & Meta > Posts/Pages > Schema Type

    You can remove the schema from a single page by going to your page > SEO settings > Schema Tab
    default

    I hope this helps. Looking forward to helping you.

    Hi Anas,

    I don’t have anything selected on that option, but the Rank Math plugin still injects WebPage schema.org code into the page.

    Is there a way to remove that on a single page?

    Hi Matt,

    From one page, if you do not have anything set on that option and still need to remove the meta tags on the header of the page code then you will need to use the hooks shown here for example – https://rankmath.com/kb/filters-hooks-api-developer/#remove-twitter-tags and here https://rankmath.com/kb/filters-hooks-api-developer/#remove-opengraph-tags

    And since its for one page then you will need to somehow check if its the actual page and then run the hooks. There is an example here https://wordpress.stackexchange.com/questions/138473/if-is-pagepage-id-not-working/251528

    Hope you can work from there.
    Cheers.

    Thanks for your reply Michael.

    I’ve verified that the hook works when set for sitewide, but when filtering for a specific page, none of the examples I tried ran the code on the page.

    One I’ve tested is this in the functions.php file:
    if( is_page( 2838 ) ) {
    add_action( ‘rank_math/head’, function() {
    global $wp_filter;
    if ( isset( $wp_filter[“rank_math/json_ld”] ) ) {
    unset( $wp_filter[“rank_math/json_ld”] );
    }
    });
    }

    I’ve also tested:
    if (is_page(346) ):
    #RMCODE
    endif;

    And:
    if (is_page( ‘Home’ ) ):
    #RMCODE
    endif;

    None of which fire the code. Is there a tested method for firing code on one page from the functions.php file?

    The ones I’ve tried online do no work.

    Hello,

    Thanks for the follow-up.

    Please use this code:

    <?php 
    global $post;
    
    if( $post->ID == 346) { ?>
    
          <!-- do your stuff here -->
    
    <?php } ?>

    And replace the 346 with the id of your page. You can get the id of your page from the address bar while editing your page https://i.rankmath.com/EI04sH (128 is the page id in this case)

    Hope this helps. Let us know if you need any further assistance.

    Hi Jaideep,

    Thanks for your reply, but I’m afraid that hasn’t worked either.

    This is the code I added into the Snippets plugin (the plugin already inserts the first PHP tag):

    global $post;

    if( $post->ID == 2847) { ?>

    add_action( ‘rank_math/head’, function() {
    global $wp_filter;
    if ( isset( $wp_filter[“rank_math/json_ld”] ) ) {
    unset( $wp_filter[“rank_math/json_ld”] );
    }
    });

    <?php }

    Hi Matt,

    Did that code work or not? Please specify.
    First make sure the if statement works for that specific page.
    You could output a html tag or something like that just to test that the code runs.

    Try adding it to the top sections of your functions.php file to make sure it runs before anything else.

    Let us know how it goes and we can take it from there.

    Hi Michael,

    No it doesn’t work, as I said in the first reply (the second just confirms the code I used).

    I’ve tested it in multiple variants to output anything on the page (including putting it first in the functions.php file), and it doesn’t display anything on the page.

    Anas
    Rank Math business

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    Thanks for getting back to us.

    Please remove any code you added previously to try and achieve this and only add the following at the bottom of your theme’s functions.php:

    
    /**
     * 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"] );
    		}
    	}
    });
    

    Replace the ID of the post with the one from the page you want to remove the schema.

    Hope this helps solve your issue.

    Don’t hesitate to get in touch if you require any further assistance.

    Thanks, that works perfectly!

    Prabhat
    Rank Math agency

    Hello,

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

    If you don’t mind us 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 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 14 replies - 1 through 14 (of 14 total)

The ticket ‘Disable Schema on One Page’ is closed to new replies.