I’m having problems finding the right hook to use for my plugin. I’m trying to 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 content right after the <body> tag.
EDIT: I know it’s three years later now, but here is a Trac ticket for anyone who is interested: http://core.trac.wordpress.org/ticket/12563
EDIT: July 31st, 2019
The linked Trac Ticket was closed as this feature was added in WordPress 5.2. You will find the Developer notes for this feature here (requires JavaScript enabled to display):
Miscellaneous Developer Updates in 5.2
I will not update the “correct answer” to one that mentions 5.2 for historical reasons, but rest assured that I’m aware and that the built-in hook is the correct one to use.
WordPress 5.2 or newer:
Use the wp_body_open hook.
WordPress 5.1 or older:
That’s kinda difficult… Most themes don’t have any hooks in that area. You could hook a javascript/html solution into
wp_footerand 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/