-
AuthorPosts
-
February 14, 2022 at 4:42 pm #1340529
Hi,
i would like to “no index” “no follow” some site of my website for privacy reasons. Specially legal notice and privacy agreement sites where my name and adress are posted. How can i do that?
Could not find an option for that. Hopefully there is a solution without a plugin, please…kind regards Jak
- This topic was modified 2 years, 8 months ago by Jak73.
February 15, 2022 at 12:01 am #1340606Hey Jak73,
Thank you for the inquiry.
You can attach a function to the wp_head hook to insert meta tags within the head element, and use the is_page conditional function to control in which pages should the meta tags render. Please check the documentations below for more info about the hook and the function.
// https://developer.wordpress.org/reference/hooks/wp_head/
// https://developer.wordpress.org/reference/functions/is_page/This is documentation about robots meta tgs.
// https://moz.com/learn/seo/robots-meta-directives
Best regards,
IsmaelFebruary 15, 2022 at 12:35 am #1340609Hi Ismael,
thanks for your reply!
Actually i’m not good at coding at all.
Could you please let me know, what tag and where i should add it.
I have just a few sites, so i could manually add these tags, if you tell me what to use, please.kind regards Jak
February 15, 2022 at 11:54 am #1340674Hi Ismael,
actually there are just to pages on my website, which i would like to set noindex, nofollow.
Isn’t there a way to set this up, without a plugin. I don’t wan’t to use a plugin just for these two pages?Kind regards
JakFebruary 15, 2022 at 2:18 pm #1340718Hi,
Thank you for update.
You can use this code in the functions.php file.
add_action( 'wp_head', function() { global $post; if ( in_array($post->ID, array(1, 2, 3) ) ) { echo '<meta name="robots" content="noindex, nofollow">'; } }, 10 );
The code above will add the robots meta tag if the current post or page ID is 1, 2 or 3. You can adjust this array and specify the pages where the meta tag should be added.
array(1, 2, 3)
Best regards,
IsmaelFebruary 15, 2022 at 2:38 pm #1340727Hi Ismael,
thanks a lot!!!
I’ll try this.
kind regards & many thanks for your help!
Jak
February 15, 2022 at 2:54 pm #1340728This reply has been marked as private.February 16, 2022 at 6:34 am #1340838Hi,
Sorry about that. We have found a minor syntax error in the code above and corrected it. Please try to add it again in the functions.php file.
Best regards,
IsmaelFebruary 16, 2022 at 9:40 am #1340874Hi Ismael,
i added the new code above to my child-theme function.php, but it seems it does not work.
Please have a look.
Kind regards Jak
February 16, 2022 at 8:51 pm #1340973Hi Ismael,
i was trying and trying, but it seems not to work?
kind regards Jak
February 18, 2022 at 4:58 am #1341259Hi,
Thank you for following up.
The code is actually working, the robots meta tag is added to the page but the default meta tag is still there. Did you install an SEO plugin? Please try to set the Enfold > SEO Support > Meta tag “robots” to the second option and let your plugin set the appropriate tags.
Best regards,
IsmaelFebruary 18, 2022 at 9:49 am #1341305Hi Ismael,
no, i did not install a seo plugin.
I tried Enfold > SEO Support > Meta tag “robots” . This removes the robot meta “index/follow” on all other pages.
The noindex/nofollow works now for selected pages.
But the robot-meta “index/follow” is now gone for every other page (i don’t have any index/follow on any other page.
Please have a look.kind regards Jak
- This reply was modified 2 years, 8 months ago by Jak73.
February 21, 2022 at 4:23 am #1341566Hi,
Thank you for the update.
We updated the filter in the functions.php file a bit. Please use this code to add the index,follow robots meta tag to the rest of the pages.
add_action( 'wp_head', function() { global $post; if ( in_array($post->ID, array(1, 2, 3) ) || is_search() || is_paged() ) { echo '<meta name="robots" content="noindex, nofollow">'; } else { echo '<meta name="robots" content="index, follow">'; } }, 10 );
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.