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 h
Creating custom hook is really easy in WordPress.
in header.php
(or anywhere you may need a hook) locate:
>
and make it:
>
That's our hook, now let's make it work.
In functions.php
add:
function body_begin() {
do_action('body_begin');
}
Now hook is ready to use, simply add any actions you need in functions.php
:
function my_function() {
/* php code goes here */
}
add_action('body_begin', 'my_function');
or JavaScript (tracking code etc - this is not the perfect way though, it is a better practice to load JavaScript from .js
files, but it is definitely better than adding JavaScript directly to template files):
function my_function() { ?>