No index code issue | WordPress.org

[ad_1]

Hi

For some reason google is indexing pages with this url ending:

/?pp=1

/feed/

Searching through internet I found similar cases that you helped fixing by using this code:

add_filter( 'rank_math/frontend/robots', function( $robots ) {
	$url = home_url( $_SERVER['REQUEST_URI'] );
	if( (strpos($url,"?pp=") !== false) )  {
		$robots["index"] = 'noindex';
		$robots["follow"] = 'nofollow';
	}
	return $robots;
});
add_action( 'template_redirect', 'noindex_feeds' );
function noindex_feeds() {
    if ( ! is_feed() ) {
        return;
    }
header( 'X-Robots-Tag: noindex', true );

I put this code in a rank-math.php file that I created in my child theme folder. But after saving, it puts all this code at the top of my page. And when I go to wp-admin to login I get a white page and the code at top.

You can see this problem in these screenshots:

https://privatebin.support-tools.com/?05d7ec9548deadbf#wcQ0H8OOS7MPUI9MABJyizoz2PQHVxBurl7VPHbK9ns=

https://privatebin.support-tools.com/?7d56a55baa25eb27#+9BLW7TAK/DxK01MH2HeeLoHw5rWeUvURdDLkDC60cc=

I removed the code for the moment because its affecting negatively my site.

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer