i’m developing a website through wordpress source code. I’m using a child theme for twenty ten, and i have a jquery file with a function that i want to incorporate in the website. My problem is: how can i call this file through “functions.php” and not by pasting the script on the html page?
I found i should use something like this:
function my_scripts() {
wp_enqueue_script( 'my-sweet-script', get_bloginfo('template_directory') . '/script.js', array('jquery') );
}
add_action('template_redirect', 'my_scripts');
And where should i put the .js file so that he doesn’t get replaced with wordpress updates?
upload js file in your template directory..
something like /wp-content/themes/my-theme/
or /wp-content/themes/my-theme/js/
this will return you the directory path of your template
this is the safe and recommended method of adding JavaScript to a WordPress generated page
this code should be added to function.php that should be found in your child theme (path ike: /wp-content/themes/my-theme/functions.php)