Can you please let me know how I can dynamically register/link to my js files in wordpress? I have two js files as below code but I do not know how to map to them uring the bloginfo() as it is taking parameters!

 <!--[if lt IE 9]>
      <script src="assets/js/html5shiv.js"></script>
      <script src="assets/js/respond.min.js"></script>


  • Is your assets folder inside your custom theme or a plugin?
    – webaware
    Commented Oct 30, 2013 at 1:30

3 Answers 3


We can use wp_enqueue_scripts action to hook js.

If it is inside theme folder then,


    function my_scripts_method() {
    get_stylesheet_directory_uri() . '/js/custom_script.js',
    array( 'jquery' )

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

// If it's for plugin,If it's for plugin, 
//use plugins_url( '/js/newscript.js' , __FILE__ )  as path.

For ref wp_enqueue_script


I´m using this code script src="?php bloginfo('template_directory'); ?>/html5/html5shiv-printshiv.js">
you only need to add the line bloginfo('template_directory') to your code to header.php
script src="?php bloginfo('template_directory'); ?>/assets/js/html5shiv.js">
I had to avoid some "<" in order to place the code.

As the code describes template directory all your JS files should be on the folders /assets/js/ within the folder template.


If you are going to use your custom js code then what you have to do is first register your custom script then enqueue it.


function link_my_js()
 //now enqueue it
//desired_name(called handle) is what you have given in wp_register_script above

now add this in a action hook


Place the codes in functions.php

If you want to use this in plugin give correct path on registering the script use plugins_url() to get the directory path then continue with yours and use it inside the plugin.

If you want to link general main jquery just use the handle name jquery alone you don't have to register it, because WordPress provides preloaded scripts in the core you can check it Here Default Scripts Included and Registered by WordPress at the bottom. Feel free to ask doubts on this:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.