I have a plugin released, and one of my customers was reporting a problem where the plugin was outputting ads in the header area of their website.
I have a function defined which contains my shortcode definitions, for example, the function contains a few of these add_shortcode( 'myshortcode', 'my_function' );
I am executing the function via the following command add_action( 'init', 'add_my_shortcodes');
Doing it thisway causes a conflich with my plugin (which outputs adsense ads) and the google analytics in the header).
I was testing different hook positions for my add_action, and it appears that add_action( 'loop_start', 'add_my_shortcodes');
If my plugin is for outputting of ads, what is the best place to hook? I need it to be available anywhere in the template, or content. For example, they can put it in posts, sidebar widgets, or straight hard coded into the theme via a do_shortcode
in their template files.
In order to ensure my shortcode is registered before any content is generated, but AFTER their header scripts, I moved my way down this list http://codex.wordpress.org/Plugin_API/Action_Reference until the ads worked properly. I ended up landing on the hook loop_start
which doesn't sound like an ideal place to hook into.
Can anyone suggest the best hook location so that it is executed before any output, but after the opening <body>
tag? I'm assuming I need to get as close to the <body>
tag as possible, but I could be wrong.
init
hook, rather than with your shortcode callback itself? Please edit your question to include your shortcode callback.init
hook works on dozens and dozens of other installations.do_shortcode
command, they should be able to. The topmost location on the page where they should be allowed to insert ads is just after the opening body tag. Therefor I don't want my shortcodes to work if they are called in the<head>
of the page. That's why I don't want to use theinit
hook, and I'd rather use a hook likebody_open
if such a hook existed.