Created
December 14, 2015 14:27
-
-
Save jfeliweb/ae47a7ceca119351f551 to your computer and use it in GitHub Desktop.
ADDING JQUERY SCRIPT TO WORDPRESS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| 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' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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