Site icon Hip-Hop Website Design and Development

When to make use of add_action(‘init’) vs add_action(‘wp_enqueue_scripts’)

In my theme’s capabilities.php, I am calling an add_action to be able to acquire a measure of management on the place jquery is loaded (within the footer together with my theme’s different scripts).

The issue I am having is that once I use add_action(‘wp_enqueue_scripts’), it solely seems to fireside if no plugins are loaded. Nonetheless, the add_action(‘init’) technique works in all instances.

I can not recall why, however I consider that add_action(‘wp_enqueue_scripts’) is most well-liked on this case. If that is true, how can I get it to work in all instances?

In capabilities.php

//if(!is_admin()){add_action('init', 'my_theme_init');} //THIS WORKS ALL THE TIME
//add_action('wp_enqueue_scripts', 'my_theme_init'); //THIS ONLY WORKS WHEN NO PLUGINS PRESENT

if(!is_admin())
{
    require_once(TEMPLATEPATH . '/functions_public.php');   
}

In functions_public.php

operate my_theme_init()
{

/* PREVENT DUPLICATE COPIES OF JQUERY FROM PLUGINS
**************************************************/
wp_deregister_script('jquery');

/* LOAD THE LOCAL WORDPRESS COPY OF JQUERY AND THEME CUSTOM SCRIPTS IN THE FOOTER
***********************************************/
wp_register_script('jquery', get_bloginfo('template_directory').'/scripts.mythemescripts.js',false,false,true);

wp_enqueue_script('jquery');

}

The 2nd technique, utilizing add_action(‘wp_enqueue_scripts’) apparently doesn’t get executed in situations the place a plugin is current that writes out script dependencies to the theme.