<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* | |
* Replace Disallow with Allow Generated Robots.txt | |
* Credit: Unknown | |
* Last Tested: Unknown | |
*/ | |
add_filter('robots_txt','custom_robots'); | |
function custom_robots($output) { | |
$public = get_option( 'blog_public' ); | |
if ( '0' != $public ) | |
return str_replace('Disallow','Allow',$output); | |
} |
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* | |
* Remove meta robots from Yoast SEO | |
* Credit: Yoast development team | |
* Last Tested: Mar 01 2017 using Yoast SEO 4.4 on WordPress 4.7.2 | |
*/ | |
add_filter( 'wpseo_robots', '__return_false' ); |
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* | |
* Change meta robots using Yoast SEO | |
* Credit: Yoast development team | |
* Last Tested: Jun 19 2017 using Yoast SEO 4.9 on WordPress 4.8 | |
*/ | |
add_filter( 'wpseo_robots', 'yoast_seo_robots_remove_search' ); | |
function yoast_seo_robots_remove_search( $robots ) { | |
if ( is_search() ) { | |
return false; | |
} else { | |
return $robots; | |
} | |
} |
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* | |
* Change meta robots using Yoast SEO | |
* Credit: Yoast development team | |
* Last Tested: Dec 12 2017 using Yoast SEO 9.2.1 on WordPress 5.0 | |
********* | |
* DIFFERENT POST TYPES | |
* Post: Change 123456 to the post ID | |
* Page: Change is_single to is_page and 123456 to the page ID | |
* Custom Post Type: Change is_single to is_singular and 123456 to the 'post_type_slug' | |
Example: is_singular( 'cpt_slug' ) | |
********* | |
* MULTIPLE ITEMS | |
* Multiple of the same type can use an array. | |
Example: is_single( array( 123456, 234567, 345678 ) ) | |
* Multiple of different types can repeat the if statement | |
********* | |
* The return false removes the robots tag on the page | |
* Or you can return index/noindex follow/nofollow like | |
* return 'noindex,follow'; | |
* Or | |
* return 'noindex,nofollow'; | |
*/ | |
add_filter( 'wpseo_robots', 'yoast_seo_robots_remove_single' ); | |
function yoast_seo_robots_remove_single( $robots ) { | |
if ( is_single ( 123456 ) ) { | |
return false; | |
} else { | |
return $robots; | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
codename2
commented
Jan 10, 2018
where can i upload this php file? |
This comment has been minimized.
This comment has been minimized.
Typically code snippets are added to your theme's functions.php file. If you're not familiar with using code snippets, these articles have wonderful advice: |
This comment has been minimized.
This comment has been minimized.
gholm
commented
Sep 18, 2018
•
If I understood correctly, the first snippet removes I'd like to take out the Edit: I think the following snippet just did it (hopefully I didn't break anything):
|
This comment has been minimized.
This comment has been minimized.
SeryozhaK
commented
Jul 11, 2019
Hi! How to noindex tag page where only 1 post? |
This comment has been minimized.
This comment has been minimized.
@SeryozhaK You or your developer can write custom code to retrieve all tag pages, count the number of posts for the tag and using the two pieces create a list of tag pages with 1 post. Once you have that list you can use the code above to write a noindex tag. However, if you have a lot of tag pages with only 1 post and you're not a really new site, your time is probably better spent removing, combining and reorganizing tags that are used infrequently. |
This comment has been minimized.
gopalkumar315 commentedAug 3, 2017
Thanks a lot, it's really useful for me....