0

I'm trying to hook into the header.php of wordpress theme(s) more specifically, right before the closing header tag </header>. I'd like to do this in a programmatic way so when I switch themes I don't have to remember to go include the method of a custom hook <?php my_cool_hook(); ?>

Is there a way to accomplish this? I've tried looking through the available actions but so far I haven't found any that would suite my needs.

Thanks.

  • 2
    Surely a header tag would be theme specific - so there is no default hook in core. – vancoder Jun 12 at 20:39
  • True, haven't thought about themes that omitted the header tag entirely. – Sergio Jun 12 at 20:41
  • I believe the Theme Hook Alliance was, at one point, trying to standardize a whole pile of hooks in various places in themes. Their GitHub repo hasn't been updated in a while, though. – Pat J Jun 12 at 20:46
  • 1
    @PatJ that would of been sweet. – Sergio Jun 12 at 20:50
0

Unless a theme provides such a hook there is no way to do this with actions and filters. If a hook is provided then it will be theme specific, no generic WP solution exists.

For a full list of the hooks that a theme should implement, see here:

https://developer.wordpress.org/themes/advanced-topics/plugin-api-hooks/

At the moment this includes:

  • wp_head() Goes at the end of the element of a theme’s header.php template file.
  • wp_body_open() Goes at the begining of the element of a theme’s header.php template file.
  • wp_footer() Goes in footer.php, just before the closing tag
  • wp_meta() Typically goes in the
  • Meta
  • section of a Theme’s menu or sidebar.
  • comment_form() Goes in comments.php directly before the file’s closing tag ()

Note that aside from wp_head and wp_footer, there is no guarantee that the theme developer knew to add them, or did so correctly, particularly wp_body_open and wp_meta

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.