How do I disable rankmath on 404 pages?

#302332
  • I have a custom plugin which constructs the url based on slugs of 2 different taxonomies and shows a relevant loop of posts that are in both taxonomies. The results pages are showing as 404, despite the archive displaying correctly. I was able to over write the headers in the plugin so that they are not 404, but then rankmath is overwriting my version. So I am back to “Page Not Found, noindex” and unable to index on google. So my question is: can i stop rankmath from working on 404 pages altogether or restrict it from working on pages where the url begins with a particular string, e.g. domain.com/places…?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting us.

    You can use the below code to disable all the meta tags of Rank Math from any URL that contains /places/:

    add_action( 'wp_head', 'rankmath_disable_features',1);
    function rankmath_disable_features() {
        $url = $_SERVER['REQUEST_URI'];
        if( strpos($url, '/places/') ){
    	remove_all_actions( 'rank_math/head');
        }
    }

    Please let us know how that goes.

    Thank you.

    thanks a million

    Prabhat
    Rank Math agency

    Hello,

    You’ve very welcome.

    Could you confirm if there’s anything else that we can assist you with or we can mark this ticket resolved?

    Looking forward to hearing back from you.

    Thank you.

    Hi there, this didn’t seem to work – I’ve cleared cache, cleared server cache – cleared everything using the tools in rank math etc… but no joy – i placed this in the top of the functions.php file of the child theme – that’s the right place yeah?

    Prabhat
    Rank Math agency

    Hello,

    You can follow this guide to add the code:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    If it still doesn’t work, we might need to take a closer look. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    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.

    I replaced your code with

    <?php
    add_action( 'wp_head', 'rankmath_disable_features',1);
    function rankmath_disable_features() {
      if (strpos($_SERVER['REQUEST_URI'], "/places/") !== false){
    	remove_all_actions( 'rank_math/head');
    	 }
    }
    ?>

    and it works, but it still stops my custom page title from working – gets replaced with just the url

    Hello,

    When you disable all Rank Math’s features on a certain page, your theme is now taking over in generating the title of your page.

    Could you please try switching to a different theme such as the default theme “Twenty-twenty”? See if the issue goes away.

    Looking forward to helping you with this one.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘How do I disable rankmath on 404 pages?’ is closed to new replies.