WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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>


share|improve this question
Is your assets folder inside your custom theme or a plugin? – webaware Oct 30 '13 at 1:30

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

share|improve this answer

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.

share|improve this answer

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:)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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