Disable RankMath in functions.php

#18832
  • Resolved Maddest
    Rank Math free

    Hello,

    my website is a mix of wordpress and native php pages. To maintain the same design on all pages, I’m using the WP header and -footer in the code of the native php pages. Here comes my problem: If I use the wordpress header then I also get the RankMath meta tags. I don’t need them on these pages and want to disable the RankMath plugin for them.

    Is there any filter for the functions.php to disable RankMath fo certain pages?

    //Disable YOAST for non WP pages
    add_action('template_redirect','remove_wpseo');
    function remove_wpseo(){
        if (get_post_type() == "") {
            global $wpseo_front;
                if(defined($wpseo_front)){
                    remove_action('wp_head',array($wpseo_front,'head'),1);
                }
                else {
                  $wp_thing = WPSEO_Frontend::get_instance();
                  remove_action('wp_head',array($wp_thing,'head'),1);
                }
        }
    }

    Are you offering a similar code snippet?

    Thanks a lot, Bernd

    PS: I need this, because RankMath adds noindex meta tags to all unknown post types (like YOAST)

    • This topic was modified 4 years, 5 months ago by Maddest. Reason: Forget something
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Yes this is also possible in Rank Math, you can use the following code:

    /*
     *
     * Disable Rank Math for non WP pages
     *
     */
    add_action( 'wp_head', 'rankmath_disable_features',1);
    function rankmath_disable_features() {
    if(get_post_type() == "") {
        remove_all_actions( 'rank_math/head');
    }
    }
    

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hey Michael, thanks a lot for your quick help. It works like a charm 🙂

    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/?rate=5#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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Disable RankMath in functions.php’ is closed to new replies.