- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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.
- Related Articles
- How do I add a simple onClick event handler to an HTML5 canvas element?
- How to add a Favicon to Your WordPress Site?
- How do I pass a variable to a MySQL script?
- How do I make an executable from a Python script?
- How do I use jQuery effects?
- How to process a simple form data using Python CGI script?
- What is a Test Script and how do I write one?
- How do I shift from jQuery to core JavaScript?
- How to Build a Simple Terminal like Website using jQuery?
- How do I select text nodes with jQuery?
- How do I add a field to existing record in MongoDB?
- How do I add a check constraint to a table in MySQL?
- How do I add a class to a given element using Javascript?
- How do I add to each row in MySQL?
- How do I check whether a checkbox is checked in jQuery?

Advertisements