3

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:

include('js/jquery.easing.1.3.js');

include('js/jquery-ui-1.8.11.custom.min.js');

include('js/jquery.transform-0.9.3.min.js');

include('js/jquery.animate-colors-min.js');

.....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.

3 Answers 3

2

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.

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

etc.

Sign up to request clarification or add additional context in comments.

3 Comments

@RadicalRaid..thanks i hv tried ur ways but its provide me netwrok err.. & u r right all js files stored in same directory. would u pls advise if hv way smthing like: <script type="text/javascript"> var templateUrl = '<?= get_bloginfo("template_url"); ?>'; </script>
Can you give me the complete error you get? My guess is there are some files missing. Maybe try it like <script type="text/javascript" src="<?php get_bloginfo('template_url'); ?>/js/scripts.js" ></script> (an extra / before js).
sry 4 late reply; having err: "NetworkError: 404 Not Found - http://localhost/tiffany/projects/jquery.easing.1.3.js". in my header file i changed it to <?php $templateDirPath = get_bloginfo( 'template_directory' ) . '/'; ?> & <script type="text/javascript" src="<?php echo $templateDirPath; ?>js/scripts.js"></script> & all of my js files stored in single folder named js
0

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');

Cheers

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');

Comments

-1

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

4 Comments

@RadicalRaid, yes you are right, but the include() function is just for PHP not for JS.
Sorry, some miscommunication there. Shouldn't bloginfo(...) be replaced by get_bloginfo(...) seeing that bloginfo(...) echoes its value directly?
@RadicalRaid the only difference between get_bloginfo() and bloginfo() is, you can use filters in get_bloginfo() otherwise everything is same like blog_info() to know more please follow the link codex.wordpress.org/Function_Reference/get_bloginfo
From codex.wordpress.org/Template_Tags/bloginfo : "It can be used anywhere within a page template. This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo()."

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.