• 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 creating the “noindex-page” custom field in the WordPress editor and putting a value in it for the desired post, but nothing occurs when checking the source code of the post.

    I’m wondering if i shouldn’t maybe create the custom field by code; 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 3 replies - 1 through 3 (of 3 total)
  • Alvind

    (@alvindcaesar)

    Hi there,

    Assuming that the “Site Wide Header” location in WPCode is hooking into the ‘wp_head’ hook, it should work. If not, you may need to reach out to their plugin support to confirm this.

    Thread Starter nobleknight

    (@nobleknight)

    Thanks, Alvind.

    I reached the WPCode support and they advised me to change the “$post->ID” with?“get_the_ID()” and it worked.

    Sorry for the GP theme developers as the issue was not related to the GP theme; great theme by the way.

    Alvind

    (@alvindcaesar)

    Awesome, I’m glad you managed to resolve that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Noindex posts only for google without plugins’ is closed to new replies.