Add HTML inside body tag on every page using plugin?
-
I am creating a plugin that needs to add a snippet of HTML as the first child of the body element on every page/post. This needs to be done by the plugin, without requiring the site administrator to edit any theme files. I know I could simply use
jQuery('body').prepend()
, but I’d rather use a more WordPress-official way of doing this – if there is one. I’ve searched but can find nothing helpful. Am I missing something?Background:
The plugin will add the Infusion UI Options component to any WordPress site. You can see this component in action here: http://build.fluidproject.org/infusion/demos/uiOptions/
The HTML for this component should be as close to the first thing in the page as possible, to ensure that it happens early in the tab order.What I’ve tried:
I’ve looked into Widgets, but as far as I can tell, they’re restricted to official sidebars, whose location is controlled by the theme. I tried creating a new sidebar for the widget, but in order to add it to the theme in the right place, either the side admin has to modify the theme files, or the plugin has to inject the code to add the sidebar, which is back tojQuery.prepend
. A Widget also seems like a bit of overkill, since what I’m doing doesn’t require any configuration at all, and I don’t need any administrative interface to allow the site admin to add or remove the component as a Widget, since this is the only thing the plugin does, so add/remove would be accomplished by adding/removing (or disabling) the plugin itself.I’ve looked through the documentation on hooks and actions and I haven’t found anything that looks like it will help me do what I want to do.
I’ve glanced at the code for a couple of plugins that allow you to add markup to the header area, and they seem remarkably long, which makes me suspect their approach would be overkill for me.
So: Is there a “WordPress way” to do what I want to do, or should I just go ahead with
jQuery.prepend
?Thanks in advance for any advice.
—
anastasia
- The topic ‘Add HTML inside body tag on every page using plugin?’ is closed to new replies.