Split: How to Set Nofollow in Search Bar Result (WordPress)

#675785
  • Resolved Anonymous
    Rank Math free

    Hi Rakibuzzaman,

    Your code works well.

    But could you help me figure out the reason that it can’t work for my other site?

    [moved to sensitive data section]

    I remembered I change some theme code to add ‘noindex & nofollow’ to my search page.

    Thanks,
    Chris

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for your patience.

    We’ve checked the site, and the internal search URL is already set to nofollow and index

    Could you please confirm if you have already resolved this issue?

    Looking forward to helping you.

    Anonymous
    Rank Math free

    Hi Reinelle,

    I think you might use the wrong search URLs.

    https://example.com/search/keyword
    https://example.com/?s=keyword

    By the way, could you help me delete the URL of my site and your screenshot?

    I thought I could edit it or remove it, this info is private.

    Thanks,
    Chris

    Hello,

    We have separated your concern into a new ticket so we can assist you accordingly. Also, your website URL has been moved to the sensitive data section and the screenshot is removed as well.

    In this case, please replace the previous filter and apply this one instead:

    add_filter('rank_math/frontend/robots', function ($robots) {
    	$url = home_url($_SERVER['REQUEST_URI']);
    	if (strpos($url, '/?s=') !== false || strpos($url,'/search/')) {
    		$robots['follow'] = 'nofollow';
    	}
    
    	return $robots;
    });

    Let us know how this goes.

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

The ticket ‘Split: How to Set Nofollow in Search Bar Result (WordPress)’ is closed to new replies.