Adding Noindex to a URL or query by functions

#264205
Viewing 9 replies - 1 through 9 (of 9 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting us.

    You can use this filter to create a condition that would apply the noindex tag based on the URL:
    https://rankmath.com/kb/filters-hooks-api-developer/#change-robots-meta

    Hope this helps.

    Thank you.

    IMK
    Rank Math free

    Thank you for your reply Prabhat Rai,

    Could you please tell me how I can add the URL?

    https://www.midominio.com/blog/projects/

    I am not a developer.

    Thank you

    Hello,

    You can use the filter given below in your theme/child theme’s functions.php file:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	global $wp;
    	$url = $wp->request;
    	If (strpos($url, 'projects') !== false) {
    		$robots['index'] = 'noindex';
    		return $robots;
    	}
    	return $robots;
    });

    This will set the page to noindex.

    Let us know how that goes. Looking forward to your update.

    Thanks.

    IMK
    Rank Math free

    Hi Jaideep,

    ¡Bravo! It works but in the Meta, the follow appears.

    http://prntscr.com/1uqbqv6

    Is it possible to add noindex and nofollow?

    Thanks

    Hello,

    Please try this code instead:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	global $wp;
    	$url = $wp->request;
    	If (strpos($url, 'projects') !== false) {
    		$robots['index'] = 'noindex';
                    $robots['follow'] = 'nofollow';
    		return $robots;
    	}
    	return $robots;
    });

    I hope that helps.

    Thank you.

    IMK
    Rank Math free

    Thanks

    Hello,

    You’re welcome, and we’re glad that helped.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

    IMK
    Rank Math free

    Works,

    Thanks

    Azib Yaqoob
    Rank Math business

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

The ticket ‘Adding Noindex to a URL or query by functions’ is closed to new replies.