Tag Info

Hot answers tagged

2

You can set the priority in hook. Priority is the 3rd parameter in the hook. In the following example, wp_enqueue_scripts will have priority of 99 which is higher than normal priority. Default priority is 10. So it will load at last function load_last_style() { wp_enqueue_style( 'style-name', get_stylesheet_uri() ); } add_action( 'wp_enqueue_scripts', ...


1

There is no action called wp_enqueue_script, it's wp_enqueue_scripts, plural, and both scripts and styles should be enqueued on that action.


1

As Rarst already noted, you answered your question. You are telling the software to load those scripts all the time. You need to control that process. Software is stupid. It can't decide when a good time is to load the code. SO... Since the plugin should only run when one of its shortcodes are called, ... Since you say the script should load only ...


1

Sounds to me like what you want to do, is create a standalone plugin for this. You've already got a lot of the ground work setup (Eg the code) it would just be a matter of creating the plugin and dropping all your code into this. You can even change retain your html template and just call it via a shortcode. Then you can retain your markup, and also use the ...


1

All scripts and styles which get included by either wp_enqueue_script() or wp_enqueue_style() get displayed in the action hook wp_head or wp_footer. So the proper moment to merge them together would be there. Hook in very early and do your magic there. The wp_enqueue_styles hook is not necessarily the best one, since it is not always the hook where the ...


1

You gave each each script the same handle/id of 'grid' Try something like this. function banana_scripts() { wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/jquery.min.js', null, null); wp_enqueue_script('grid2', get_stylesheet_directory_uri() . '/js/main.js', null, null); } add_action('wp_enqueue_scripts', ...


1

There's a much better and more reliable way than naming your plugin "ZZ" - use a delayed hook on plugins_loaded, which fires after all plugins are loaded: function wpse_191178_plugins_loaded() { // Do your stuff } add_action( 'plugins_loaded', 'wpse_191178_plugins_loaded', 100 );


1

Scripts should be enqueued on wp_enqueue_scripts action hook, which runs after init action. So dequeuing on init won't work because sripts are not enqueued yet. Before enqueued scripts are printed, wp_print_scripts action is triggered so you can dequeue or unregister scripts safely at this moment: add_action( 'wp_print_scripts', 'drw_timelinr_dequeue' ); ...



Only top voted, non community-wiki answers of a minimum length are eligible