You should place the whole function/script inside a so called IIFE like this:
(function($){
//your code
})(jQuery);
In WordPress the $ isn’t attached to jQuery by default due to possible conflicts with other JavaScript libraries.
Related Posts:
- WordPress Ajax always returns a 404 error
- Calling a method from functions.php on a click of a button
- Nice scroll to wordpress
- Javascript code inside “” in core WordPress files .php
- Minify HTML, CSS, JS with PHPWee?
- Slide in Panel WordPress Post
- Show post in slider
- Populate dropdown with Child Pages based on Parent Page chosen
- search and replace preword from author
- How to change redirection route to a php page for making it only accessible by logged-in members?
- parts of url disappear when using # inside href=”” [closed]
- Noscript not working as it should in wordpress site
- Add Codepen animation as Preloader to WordPress
- HTML escaping data with ajax requests
- Override user-edit.php to design own profile page
- Calling PHP Titles inside Javascript Markup
- Link to page with posts of specific type
- Replacing WordPress Icons (menu,icons32, etc)?
- Is it possible to isolate and use WordPress functions outside of wordpress
- Time Delay a URL Redirect for Specific Page
- Cascading dropdown select search based on Parent Page & Child Page
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Display WordPress search results based on the selected Sub-Category
- html form: redirect page after form completes submit function and posts data
- WordPress User Meta value variable into Google Gauge Chart
- Search bar for wp menu
- Adding HTML Code to Replace Text in PHP
- Executing php on button press
- Add other class content with reference class value
- Using Google Analytics in an enqueued JS file
- separate list of programs in html/javascript coming from php
- How to use wp_ajax_set_post_thumbnail?
- Passing a value from an input field to a php function in WordPress?
- How do I disable cache for a certain page?
- WordPress Slider is not working
- Show subcategory name selected in specific category woocoommerce
- sessionStorage saves input value in browser but it is not loaded in the form field
- Collapsible menu on post sidebar only expands and does not collapse
- Target a specific container to style on WordPress storefront theme
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Where to find the html for WordPress site? [closed]
- I need help implement a Javascript code into the PHP file
- Trying to customize wordpress drop down categories
- Is there a better way to output HTML as a shortcode?
- Load wp_editor on button click
- Slick slider not working on wordpress
- start_lvl Ignored in Custom walker_nav_menu
- What exactly does “Posts page” do in WordPress?
- Adding a search form inside a div
- Load custom field value into div with AJAX
- Where exactly do I write define( ‘WP_DEBUG’, true ) in wp-config file
- How to display blog images using wordpress in existing project
- WordPress automatically adds tags when pasting code, how to stop it?
- Using shipped version of jquery
- Bridging TinyMCE js and WordPress PHP?
- class click counter save number
- My form action url is being prepended with a directory that does not exists
- custom fields wordpress
- How does wp_enqueue_scripts work?
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- How do I add a custom css to all posts without affecting homepage css? [closed]
- How do I Import / Upload Files with jQuery AJAX?
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- HTML table attributes ignored
- How to rename woocommerce-billing-fields
- How to use wordpress function wp_enqueue_script() in php?
- url_to_postid returns 0
- How do i add slugs to a URL, but still redirecting to the same page
- Calling function in loop causes repeat data
- implementing a jQuery “click to expand” link in WordPress [closed]
- random reason on refresh
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Some problems in custom widget
- Call a function in functions.php from within tags (JS)
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress Search Ajax + Isotope + InfiniteScroll
- Create a WordPress Contact Form to call a POST AWS API Gateway and send user data
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- couldnt show short code atts in category
- WooCommerce multiple custom fields code
- How to override html codes in wordpress?
- Create html tree sitemap
- Force ‘permanent’ post cache of shortcode results
- Font-Family does not looks like how it should be [closed]
- What is the best way to get the first few post from WordPress in different divs using a loop?
- Run php function after html click after page refresh
- Get all the contents of taxonomy and sort by term
- Gallery requires a featured image but does not show it in posts/pages
- How to style this wp_list_pages markup
- How To: Simple domPDF Example
- Cant get theme to change footer color through theme customizer
- How do I modify the with wp_nav_menu()
- notify users when changed database
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Having trouble customizing toolbar on wp_editor
- how to escape alert/window.location.replace with variable
- Registered a REST Route but I’m Getting a 400 Bad Request
- Add custom data attribute to every core Gutenberg Blocks