I am trying to add some js to the head using add_action('wp_head', 'js_func');
which works when posted just after the function, however I do not want it posted on every page, just the page that it’s relevant to and I am trying to do it like so
function things_to_do_on_this_page() {
add_action('wp_head', 'js_func');
//other functiony things
}
However when it is called like so the js isn’t placed at all, thus breaking the page.
Is it possible to do this?
If you want to find out whether you’re on a specific page, post, in a category archive, etc., then core has to offer Conditional Tags for this.
If you want to hook a js-script definition, then a better way to do this is the following:
EDIT
You can sum up/collect all your little functions, that get hooked somewhere and put the
add_action
calls into a function that gets loaded on the first hook that’s available to themes:after_setup_theme
. Important is that the child themes functions.php gets loaded first, then the parent themes and then theafter_setup_theme
hook. So you can let the possibility open to change things from inside your parent or child theme.But to answer your question: Yes, you can call every global function inside another function.