

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- 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 use jQuery effects?
- What is a Test Script and how do I write one?
- How to process a simple form data using Python CGI script?
- 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?
- How do I display real-time graphs in a simple UI for a Python program?
- How do I put a jQuery code in an external .js file?
- How to do simple Arithmetic on Linux Terminal?
Advertisements