[Resolved] Adding custom_header using GP hook

Home Forums Support [Resolved] Adding custom_header using GP hook

Home Forums Support Adding custom_header using GP hook

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #453075
    B

    Hi,

    In order to add some custom code / functionality to just one page of my site, I’ve set up a custom_header under the “Custom Fields” metabox together with the following code added to the header.php file (just above the closing </head> tag):

    <?php if (is_page()) {
    if ($custom_header = get_post_meta($post->ID, ‘custom_header’, true)) {
    echo $custom_header;
    }
    }
    ?>

    This works fine, but I’d rather place the above code within a hook rather than editing the header.php file.

    As per your advice in previous thread, I’ve tried adding the above lines of code to wp_head instead of in header.php, but it didn’t seem to work (i.e. there is just a blank space on the page between the navigation bar and footer).

    It’s working fine when I have the lines of code inserted directly in header.php, so I’m guessing it’s not executing when included in wp_head? I’ve double checked and I do have the Execute PHP box ticked (and Disable hook is empty i.e. unchecked). Please advise whether my code above is correct for inclusion in wp_head and that wp_head is the correct hook to be using.

    Many thanks

    #453180
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Perhaps try in the Before Header hook? That should place the code in the exact place you’re adding it in header.php.

    Also, instead of $post->ID, try get_the_ID().

    #453207
    B

    Excellent!!

    Thank you Tom, that’s fixed it.

    Many thanks

    #453421
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

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