• Resolved nobleknight

    (@nobleknight)


    Hi. I’m trying to allow noindexing posts and pages (for Google) through a custom field using this code:

    $noindex = get_post_meta($post->ID, 'noindex-page', true);
    
    if ($noindex) {
        echo '<meta name="googlebot" content="noindex,follow" />';
    }

    The code needs to be in the header, so I’m setting the location in WPCode to “Site Wide header” and activated it.
    I’m putting a value in the “noindex-page” custom field for the desired post, but nothing occurs when checking the source code of the post.

    Could you please advise me on how to solve this issue?

    Thank you very much.

    PS: I’m using:
    – WordPress: 6.4.3.
    – GeneratePress Theme: 3.4.0.
    – WPCode Lite: 2.1.10.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @nobleknight,

    Please try using “get_the_ID()” instead of $post->ID there or add “global $post” before the snippet you shared.

    Thread Starter nobleknight

    (@nobleknight)

    Thank you very much, Mircea.

    I changed the “$post->ID” to “get_the_ID()” and it worked.

    You saved me a lot of time and effort.

    Thanks again for your great assistance (even though the source of the issue was not related to the plugin).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP snippet code in header (for noindexing) doesn’t work’ is closed to new replies.