68 votes
Accepted

Annoying "JQMIGRATE: Migrate is..." in console after update to WordPress 4.5

WordPress uses the jQuery migrate script to ensure backwards compatibility for any plugins or themes you might be using which use functionality removed from newer versions of jQuery. With the release ...
Andy's user avatar
  • 1,017
60 votes

Enqueue core jQuery in the footer?

Here's another option which avoids having to de-register and re-register: /** * Move jQuery to the footer. */ function wpse_173601_enqueue_scripts() { wp_scripts()->add_data( 'jquery', '...
Matthew Boynes's user avatar
47 votes
Accepted

Update jquery version

Warning: You shouldn't replace core jQuery version, especially in the admin panel. Since many WordPress core functionality may depend on the version. Also, other plugin may depend on the jQuery ...
Fayaz's user avatar
  • 8,909
36 votes
Accepted

Why does WordPress use outdated jQuery v1.12.4?

There are many themes and plugins using jQuery as loaded by WP core. Every time jQuery is updated, there is a risk of older themes and plugins breaking (because lots of them are still used but no ...
cjbj's user avatar
  • 14.5k
24 votes

Enqueue core jQuery in the footer?

A better solution: add_action( 'wp_default_scripts', 'move_jquery_into_footer' ); function move_jquery_into_footer( $wp_scripts ) { if( is_admin() ) { return; } $wp_scripts->...
NextGenThemes's user avatar
23 votes
Accepted

ajax live search for post title

Here is a working solution (tested as is) The HTML (could be part of page content) <input type="text" name="keyword" id="keyword" onkeyup="fetch()"></...
Ahmed Fouad's user avatar
  • 1,343
23 votes

Why does WordPress use outdated jQuery v1.12.4?

It's not outdated Moving to 2.x or 3.x is too early, people still use IE8 which is only supported on 1.x
Nabil Kadimi's user avatar
  • 2,686
18 votes

Is there a way to enable Cross-Origin Resource Sharing for WordPress' ajaxurl?

Milo is correct. For instance, go to your theme's functions.php file, and add the following: add_filter( 'allowed_http_origins', 'add_allowed_origins' ); function add_allowed_origins( $origins ) { ...
Julian's user avatar
  • 289
16 votes

Update jquery version

I have developed a plugin for this specific problem. The plugin doesn't mess with WordPress jQuery as it is only loaded in the front-end. See: jQuery Manager for WordPress Why yet another jQuery ...
Remzi Cavdar's user avatar
  • 1,176
15 votes

How to add a javascript snippet to the footer that requires jQuery

Since wordpress 4.5 you can add inline script by wp_add_inline_script(). To add a javascript snippet to the footer that requires jQuery, this code helps you function enqueue_jquery_in_footer( &$...
Dhinju Divakaran's user avatar
13 votes

WordPress AJAX File Upload - FrontEnd

Hi You have Use this COde For WordPress front-end AJAX file upload tutorial Code Here is my code: In my template file example.php <form enctype="multipart/form-data"> <input type="text" ...
Adnan Limdiwala's user avatar
10 votes
Accepted

WordPress 5.2.1 deactivated my jQuery

5.2.1 includes a backported fix from jQuery 3.4.0 (commit). Because they're now using a modified version of jQuery they suffixed the version number with '-wp': $scripts->add( 'jquery', false, ...
Rup's user avatar
  • 4,257
9 votes

How to add a " waiting" icon for an ajax in WP frontend?

You can use the inbuilt spinner class : Add the class to the HTML where you want the spinner to appear, for example after your search button : <button type="button" id="searchsubmit">Search ...
NJENGAH's user avatar
  • 379
9 votes

Annoying "JQMIGRATE: Migrate is..." in console after update to WordPress 4.5

You could change the log message text to blank in jquery-migrate.min.js but this will not be preserved on core update. The alternative is to add passthrough/filter function copy of console.log to ...
majick's user avatar
  • 5,081
9 votes
Accepted

How to modify wp.media to get and display multiple images

So, this works. I'd be happy to implement and credit improvements! /** * @Script: WordPress Multiple Image Selection in jQuery * @Version: 0.1 * @Author: CK MacLeod * @Author URI: http://...
CK MacLeod's user avatar
  • 1,857
8 votes

Check if user is logged in using JQuery

Please note that none of the above examples are reliable in case you use a page cacheing plugin, then the code in body tag will be static. Also there is a simple way to do this (with no extra query to ...
Janos Szabo's user avatar
8 votes

AJAX nonce with check_ajax_referer()

Difficult to say for sure where the mistake is as you have not mentioned about your add_action('wp_ajax_my_function','whatever_callback');which I think you missed out on that. But your question is ...
db306's user avatar
  • 338
8 votes

Annoying "JQMIGRATE: Migrate is..." in console after update to WordPress 4.5

Just a little test here. I peeked into jquery-migrate.js and noticed this part: // Set to true to prevent console output; migrateWarnings still maintained // jQuery.migrateMute = false; so I tested ...
birgire's user avatar
  • 67.1k
8 votes
Accepted

Using '$' instead of 'jQuery' in WordPress

Using a self invoking anonymous function that passes the jQuery object will do the trick: (function($){ $(window).load(function(){ $('#myid').css({'background': 'black', 'color':'white'}); ...
Dave Romsey's user avatar
  • 17.7k
8 votes
Accepted

Wordpress Ajax URL for function in functions.php

//ajax call var data = { action: 'folder_contents', path: datafolder }; var ajaxurl = baseurl + ''; //WHAT IS THIS?!?! jQuery.post(ajaxurl, data, function(response) { alert('Got this ...
Tex0gen's user avatar
  • 572
8 votes
Accepted

Do I need both jquery.js and jquery-migrate.min.js?

As stated in the official blog of jQuery. Note that WordPress is mentioned in the quote. jQuery Migrate 1.4.1 released, and the path to jQuery 3.0 Version 1.4.1 of the jQuery Migrate plugin has been ...
Den Isahac's user avatar
8 votes
Accepted

Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)

Here's my take on it, although a bit late, but I am working on converting all jQuery.ajax() calls to vanilla JavaScript, so why not. // alpha JS request // no jQuery // https://developer....
Ciprian's user avatar
  • 875
8 votes
Accepted

How to get the path to current theme, but from a JS file?

You can use wp_localize_script to pass an object with the url to load before the file. and then in the file you can use it like testpage_obj.json_data wp_register_script('testpage', ...
Shibi's user avatar
  • 1,813
8 votes
Accepted

possible to make sections in theme customizer sortable and saveable at publish button clicked?

Simple tutorial - How to sort customizer sections in the panel and add order to theme. 1. You must use prefixes to do this because customizer don't support custom classes. ctmss_panel_ - for panels ...
Michael's user avatar
  • 172
7 votes

Annoying "JQMIGRATE: Migrate is..." in console after update to WordPress 4.5

Solution: add this to functions.php: function remove_jquery_migrate_notice() { $m= $GLOBALS['wp_scripts']->registered['jquery-migrate']; $m->extra['before'][]='temp_jm_logconsole = ...
T.Todua's user avatar
  • 5,789
7 votes
Accepted

Retrieve POST data from AJAX call

Problem "Serialization" is the act of turning a data-object into a string-representation. jQuery automatically serializes the data property before sending an AJAX request. The server then ...
bosco's user avatar
  • 6,805
7 votes
Accepted

Deregister WordPress jquery on specific page

Hook to wp_enqueue_scripts. It will do the trick. Modified code is- if (!function_exists('modify_jquery')) { function modify_jquery() { if (is_page(array('page 1', 'page 2'))) { ...
CodeMascot's user avatar
  • 4,527
7 votes
Accepted

Dynamically update post title in admin page

The block editor is restoring back the title that was last saved (or typed manually into the textarea), so with the block editor, you can change the title dynamically using this code: wp.data....
Sally CJ's user avatar
  • 39.2k
6 votes
Accepted

AJAX call returns 0

Note that the action should be inside the data key. In your post request there is no key named as action therefore, the callback function is never being called. Consider this example:- jQuery.ajax({...
Sumit's user avatar
  • 4,794
6 votes

Create shortcode to echo javascript

First of all, it looks like you are trying to enqueue version 2.2.4 of jquery, under the condition that jquery has already been loaded. That doesn't look good. Secondly, you can't just echo a script ...
cjbj's user avatar
  • 14.5k

Only top scored, non community-wiki answers of a minimum length are eligible