Mass update page IDs with noindex

#58236
  • Resolved Anonymous
    Rank Math free

    Hi,

    What would be the best way to mass update pages with noindex, noarchive and nosnippet values?

    If there are over 100 pages to noindex, it would be time-consuming to edit each page individually. Please advise if a code snippet would be possible such as passing in the IDs of all the pages?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    I can suggest that you create some code to modify the frontend robots meta only for certain page IDs by making use of the following filter:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	return $robots;
    });

    I hope this info helps. Thank you.

    Anonymous
    Rank Math free

    Hi there,

    Thanks, but how would I pass in the noindex, noarchive and nosnippet with this filter? Please could you provide the complete code snippet for this.

    Thank you

    Alberto
    Rank Math business

    Hello,

    Here you have (you will need to modify it to work only in the page IDs you want):

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
            $robots['index'] = 'noindex';
            $robots['noarchive'] = 'noarchive';
            $robots['nosnippet'] = 'nosnippet';
    	return $robots;
    });

    Looking forward to help you.

    Anonymous
    Rank Math free

    Thanks, if anyone else needs this, this is the final code that works:

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	global $post;
    	// add your page IDs into the array below
    	if( is_page( array( 1, 2, 3) ) ) {
    		// noindex etc
    		$robots['follow']    = 'nofollow';
    		$robots['index']     = 'noindex';
                    $robots['noarchive'] = 'noarchive';
                    $robots['nosnippet'] = 'nosnippet';
                    return $robots;
            }
    	return $robots;
    });
    Michael Davis
    Rank Math pro

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

The ticket ‘Mass update page IDs with noindex’ is closed to new replies.