Exclude One Page for RankMath rules

#602125
  • Resolved Anonymous
    Rank Math free

    Dear

    I’m testing RankMath as a replacement for All in SEO, but I’ve run into a problem and would like to ask for help.

    I would like to exclude only one WordPress page in Rank Math title/description rules. It would be possible?

    On my site, I have a page with dynamic content, which comes from outside the WordPress database. For this page, I have a rule in my WordPress theme. Something like:


    <?php if ( is_page( 'lutador' ) ) { ?>

    <title><?PHP global $fighter; echo $fighter['name'];?></title>

    <meta name="description" content="Saiba todas as informações do lutador <?PHP echo $fighter['name'];?>, o <?PHP echo $fighter['nick_name'];?>. + custom description" />>

    However, when I activate RankMath, this theme function does not work.

    Could you help me please?

    I would like the above PHP code to be read in priority to RankMath or I would be able to exclude only the ‘fighter’ page from the plugin rules.

    Kind Regards

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math support and we apologize for the inconvenience.

    One way to achieve this with Rank Math is to use a filter to override Rank Math’s title and description for that specific page. Here are the steps:

    To use a filter to override Rank Math’s title and description, you will need to add some custom code to your child theme’s functions.php file or use a plugin like Code Snippets to insert it.

    You can use the rank_math/frontend/title and rank_math/frontend/description filters to change the title and description programmatically. You can find more information about these filters here: https://rankmath.com/kb/filters-hooks-api-developer/#change-the-title and https://rankmath.com/kb/filters-hooks-api-developer/#change-meta-description

    To use these filters, you will need to add a condition that checks if the current page is the one that you want to exclude, and then return your custom title and description. For example, if your page slug is ‘lutador’, you can use this code:

    Meta Title:

    add_filter( 'rank_math/frontend/title', function( $title ) {
    	if ( is_page( 'lutador' ) ) { //check if the current page is 'lutador'
    		global $fighter; //get the global variable $fighter
    		return $fighter['name']; //return the custom title
    	}
    	return $title; //return the original title
    });

    Meta Description:

    add_filter( 'rank_math/frontend/description', function( $description ) {
    	if ( is_page( 'lutador' ) ) { //check if the current page is 'lutador'
    		global $fighter; //get the global variable $fighter
    		return 'Saiba todas as informações do lutador ' . $fighter['name'] . ', o ' . $fighter['nick_name'] . '. + custom description'; //return the custom description
    	}
    	return $description; //return the original description
    });

    These are of course just examples, you’ll need to customize the filter to work for your specific need. You can learn how to add filters to your site here: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    We hope this helps. If you have any other questions or concerns regarding Rank Math, please feel free to contact us again. We are always happy to help.

    Thank you for choosing Rank Math!

    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 1 replies (of 1 total)

The ticket ‘Exclude One Page for RankMath rules’ is closed to new replies.