- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I add a simple jQuery script to WordPress?
WordPress is an open source CMS, used to develop dynamic websites. Let’s learn how to add jQuery script to WordPress. In the WordPress Theme folder, create a folder "js", and add a file in that. That file will be your Query file with extension “.js”. Add your jQuery script to that file. We have named it new.js,
Here’s your jQuery script:
jQuery(document).ready(function($) { $('#nav a').last().addClass('last'); });
Open your theme's functions.php file. Use the wp_enqueue_script() function so that you can add your script.
Here’s the code:
add_action( 'wp_enqueue_scripts', 'add_my_script' ); function add_my_script() { // name your script to attach other scripts and de-register, etc. wp_enqueue_script ( ‘new', get_template_directory_uri() . '/js/add_my_script.js', array('jquery') // this array lists the scripts upon which your script depends ); }
Assuming that your theme has wp_head and wp_footer in the right places, this will work.
Advertisements
To Continue Learning Please Login
Login with Google