[Resolved] Adding user code in header

Home Forums Support Adding user code in header

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1060311
    Yann

    Hi there,

    I would like to add the following code in the header, but without editing the header.php (easy way) because I will lose it at the next template update.

    So, it is possible or not ? (user css refuses it)

    <?php if ($post->ID == 2312) { echo ‘<meta name=”robots” content=”noindex,nofollow”>’; } ?>

    Thanks.

    #1060370
    David
    Staff
    Customer Support

    Hi there,

    you can use the Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

    The wp_head hook will place it inside the header, you can also use the Display Rules to assign where you want to output the meta instead of including the conditional in your code.

    #1060878
    Yann

    Thanks David,

    I found that incredibly complex.
    I did try but the meta was put inside the body when I was expecting it to be at the very top of the <header>.
    I will keep my change in the header.php as it works fine.
    Thanks anyway.

    regards.

    #1061180
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    The wp_head hook exists inside the <head></head> element of your site, so if you choose that hook, it shouldn’t display within the body of the site.

    Alternatively, you can use a function:

    add_action( 'wp_head', function() {
        // Your PHP in here.
    } );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.