Skip to content

Instantly share code, notes, and snippets.

@jfeliweb
Created December 14, 2015 14:27
Show Gist options
  • Select an option

  • Save jfeliweb/ae47a7ceca119351f551 to your computer and use it in GitHub Desktop.

Select an option

Save jfeliweb/ae47a7ceca119351f551 to your computer and use it in GitHub Desktop.
ADDING JQUERY SCRIPT TO WORDPRESS
/**
Add the following code: in function.php
That’s it. The jQuery library and my_script.js will now be loaded within the <head></head> area of every page of your WordPress site except the admin pages.
**/
function add_my_script() {
wp_register_script('my_script', home_url() . '/wp-content/themes/mythemename/js/my_script.js', array( 'jquery' ));
wp_enqueue_script('my_script');
}
add_action( 'wp_enqueue_scripts', 'add_my_script' );
//Create a new JavaScript file and place it in your theme folder. For this example, a file called my_script.js is placed in a subfolder (js) of the theme folder, like this: mythemename/js/my_script.js. Below is an example of a simple jQuery script that could go into the my_script.js file:
jQuery(document).ready(function() {
jQuery("#my-div").hover(function() {
jQuery("#my-other-div").show();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment