Register and enqueue a script
-
Hi, I’m learning how things work in wordpress and recently I’ve learned something about enqueuing and registering scripts. Thing I don’t get is why do we need to register a script and then enqueue it when we can just use enqueue function? Only practical use I see in this is deregistering and then registering a different version of jquery. To put it short is there any point in writing
function my_jquery_script() { wp_register_script( 'my-script', get_template_directory_uri() . '/js/my-script.js', array( 'jquery' ) ); wp_enqueue_script( 'my-script' ); } add_action( 'wp_enqueue_scripts', 'my_jquery_script' );when we could just do this:
function my_jquery_script() { wp_enqueue_script( 'my-script', get_template_directory_uri() . '/scripts/my-script.js', array( 'jquery'), '1.0', false ); ; } add_action('wp_enqueue_scripts', 'my_jquery_script');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Register and enqueue a script’ is closed to new replies.