views:

35

answers:

3

Hello,

One of the things that drives me crazy about wp devolopement is I'm never able to find the right hook so I figured I would ask here. What I'm trying to do is add a message to the top of each page by having my plugin add a function. What's the best hook to use. I want to insert conent right after the <body> tag.

Thanks

+1  A: 

That's kinda difficult... Most themes don't have any hooks in that area. You could hook a javascript/html solution into wp_footer and display it at the top of the page... sort of how Stack Overflow does it, or how Twitter does their notifications.

This is the best reference for all the hooks included in WordPress: http://adambrown.info/p/wp_hooks/

Dennis Pedrie
Oh I like that idea! :)
BandonRandon
Also any suggestions of good (GPL) scripts that will accomplish this?
BandonRandon
A: 

Alternatively, if you are creating the theme yourself and/or can modify it, you can create an action yourself using WordPress' do_action function. This is also how they create their other hooks. So basically in your theme, you would go where you want to, right after the <body> tag, and do something like:

do_action('after_body');

You can also pass arguments to the action callback, see the linked documentation for information.

Then afterwards, you would simply use the add_action function to hook onto it.

add_action('after_body', 'my_callback');

Hope that helps. Sorry if I misunderstood.

Jorge Israel Peña
The concept makes sense the problem is I'm trying to display an optional notification at the top of the page of any theme inside of WordPress.
BandonRandon
Yeah, then Dennis' response would be the best way to go about it I would think :)
Jorge Israel Peña
A: 

In this scenario, what i do is: Use Jquery to append or prepend things:

http://api.jquery.com/prepend/

Bye.

josoroma