Home » Wordpress » how to create template path for .js file in wordpress

how to create template path for .js file in wordpress

Posted by: admin November 30, 2017 Leave a comment


i just lrned how to create template path for .js file-

<script type="text/javascript" src="<?php bloginfo( 'template_directory' ); ?>js/scripts.js" ></script>

but inside my ‘scripts.js’ file has included some .js files like below:





…..and so on

any1 pls help me how can i make path for those included .js file in easiest way. i’m vry new in wordpress.


You can probably just change it to

include( "jquery.easing.1.3.js" );

etc. So without the “js/”.

If I understand correctly, you’re including files in the javascript file scripts.js that are in the same directory.

Including files without prepending a / always means you’re searching through the current directory. So basically, you’re trying to include js/js/jquery.easing.1.3.js, which doesn’t exist.

If you’re trying to use a PHP include inside a Javascript file, it will not work. You shouldn’t do the including in the Javascript file anyway, just do it in the file you’re including scripts.js as such:

<script type="text/javascript" src="<?php get_bloginfo('template_url'); ?>js/scripts.js" ></script>
<script type="text/javascript" src="<?php get_bloginfo('template_url'); ?>js/jquery.easing.1.3.js" ></script>



Here is the code to include the JS files in the theme:

include(get_bloginfo('template_url') . 'js/jquery.easing.1.3.js');
include(get_bloginfo('template_url') . 'js/jquery-ui-1.8.11.custom.min.js');
include(get_bloginfo('template_url') . 'js/jquery.transform-0.9.3.min.js');
include(get_bloginfo('template_url') . 'js/jquery.animate-colors-min.js');


Or if your purpose is to embed all JS files contents in one JS file, you should use the following, This will use the file path of the files, not the URL addresses:

include(get_template_directory() . 'js/jquery.easing.1.3.js');
include(get_template_directory() . 'js/jquery-ui-1.8.11.custom.min.js');
include(get_template_directory() . 'js/jquery.transform-0.9.3.min.js');
include(get_template_directory() . 'js/jquery.animate-colors-min.js');


bloginfo( 'template_directory' );

is the correct way because wordpress themes require the complete path.

and if you want to use include() then use something like this :

include(bloginfo('template_directory') . 'js/jquery.easing.1.3.js')