-
I’ve been reading up a bit on this subject, but the more I read – the more confused I get.
-
Can someone explain to me in short what’s the exact difference between
wp_enqueue_scripts
,wp_register_scripts
andwp_print_scripts
? -
For example, I have the following code in my functions.php – and it’s working, but I do not understand why I can not use
wp_print_scripts
for the stylesheets, whereas the code still works if I usewp_enqueue_scripts
for the javascript files:add_action('wp_print_scripts', 'add_my_js'); function add_my_js(){ if(!is_admin()){ wp_enqueue_script('default', get_bloginfo('stylesheet_directory').'/js/default.js', array('jquery')); } } add_action('wp_enqueue_scripts', 'add_my_stylesheet'); function add_my_stylesheet() { wp_register_style('default', get_bloginfo( 'stylesheet_url')); wp_enqueue_style( 'default'); }
Leave a Reply
You must be logged in to post a comment.
wp_print_scripts
is the action that runs when scripts are output to the template.wp_register_script
andwp_enqueue_script
are functions for registering/enqueueing scripts to be output whenwp_print_scripts
runs.you can’t register or enqueue styles in the
wp_print_scripts
action hook because styles have already been output in thewp_print_styles
hook, which runs beforewp_print_scripts
.refer to the action reference to see the order things are executed in in a request: