Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #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, 9 months ago by Jak73.
    #1340606

    Hey 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,
    Ismael

    #1340609

    Hi 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

    #1340674

    Hi 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
    Jak

    #1340718

    Hi,

    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,
    Ismael

    #1340727

    Hi Ismael,

    thanks a lot!!!

    I’ll try this.

    kind regards & many thanks for your help!

    Jak

    #1340728
    This reply has been marked as private.
    #1340838

    Hi,

    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,
    Ismael

    #1340874

    Hi 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

    #1340973

    Hi Ismael,

    i was trying and trying, but it seems not to work?

    kind regards Jak

    #1341259

    Hi,

    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,
    Ismael

    #1341305

    Hi 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, 9 months ago by Jak73.
    #1341566

    Hi,

    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

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.