Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does anyone know a good way to hook just after get_header() without hacking the theme? I know you can hook before the function loads header.php but I am trying to insert some HTML just after get_header() is finished.

share|improve this question
add comment

1 Answer 1

I hate answering questions in the negative because it is easy to go wrong, but there is no core hook that does that-- at least no hook that I have ever seen. I admit it could be handy for a couple of things though.

wp_header() loads the theme's header file. That is about it. It is really just an amped-up include. If you look at the source, there is a hook that runs before the header file is loaded, but not one after.

It is possible that your theme has provided a hook though. I am thinking that that is the only chance you have of this working.

You could do this with Javascript, if that is an option, then you could hook the script to wp_head and wouldn't need to hack the theme. That is, you could load Javascript into the page <head> using the wp_head hook, and that Javascript could insert your HTML into the page body. It is not a great solution but given your condition about not editing the theme and given that there are no hooks you can rely on across multiple themes, that is the best I can think of.

share|improve this answer
    
+1. wp_head is the correct template action to use to add HTML to the document head. If the intent is to add content to the document body, then you'll have to wait for Twenty Thirteen, which will include standard template hooks. –  Chip Bennett Feb 20 '13 at 16:08
    
Standard template hooks? I am intrigued. –  helgatheviking Feb 20 '13 at 17:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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