Site logo

Archived topic

Adding user code in header

3 replies · Started by virtualsim on November 12, 2019

Viewing posts 1–4 of 4

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.

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.

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.
} );
This archived topic is closed to new replies.