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 released. It has only a few changes but the most important of them fixes a problem with unquoted selectors that … Read more

Passing boolean values with wp_localize_script

Try this: $options = get_option( ‘theme’ ); wp_localize_script( ‘flexslider’, ‘flex_vars’, array ( ‘flex_auto’ => ($options[‘slide-auto’]) ? ‘true’ : ‘false’, ‘flex_animation’ => $options[‘slide-animation’], ‘flex_direction’ => $options[‘slide-direction’] ) ); Assuming slide-auto is the option you made a boolean. This script isn’t tested, I directly typed it in here.

Correct Method to run scripts with dependencies without enqueue?

function script_that_requires_jquery() { wp_register_script( ‘script-with-dependency’, ‘http://www.example.com/script-with-dependency.js’, array( ‘jquery’ ), ‘1.0.0’, true ); wp_enqueue_script( ‘script-with-dependency’ ); } add_action( ‘wp_enqueue_scripts’, ‘script_that_requires_jquery’ ); This is the correct method to enqueue scripts (and styles for that matter). You should always be using wp_enqueue_scripts to hook scripts and styles to. There are a few thing here to check when you … Read more

CSS not pulling in for jQuery UI dialog

There is no jquery-ui-dialog style defined in WordPress Out of the box, you need to ue the stylesheets manually, when i needed to enqueue the jQuery-UI style i pulled it from google api CDN wp_enqueue_style(‘jquery-style’, ‘http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css’); but you can enqueue a local copy if you want like this: wp_enqueue_style( ‘myStylesheet’, WP_PLUGIN_URL . ‘/path/stylesheet.css’ );

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 ) { $origins[] = ‘https://site1.example.com’; $origins[] = ‘https://site2.example.com’; return $origins; } Now an ajax call from https://site1.example.com to your site’s ajax url will have the appropriate Access-Control-Allow-Origin header in the response. eg. $.ajax({ … Read more

Display Media Uploader in Own Plugin on WordPress 3.5

Only Uploader below a example code, works only on post edit page. If you will use also on other page, then include the function wp_enqueue_media(), see the next headline. jQuery(document).ready(function($) { var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; $(‘.stag-metabox-table .button’).click(function(e) { var send_attachment_bkp = wp.media.editor.send.attachment; var button = $(this); var id = button.attr(‘id’).replace(‘_button’, ”); _custom_media … Read more

Using jQuery to delete data stored in wp_options

Ajax in WordPress works by sending an HTTP post to /wp-admin/admin-ajax.php (by default) that then fires the corresponding hook. So, you attach some jquery to an event triggered by your delete button, which then posts to admin-ajax.php, which has an action, say, delete_my_options(), which actually runs the php to delete. Then, you have a function, … Read more

ajax stopped working when not logged in?

Edit: I’ve kept my original answer below, however, I’m not sure what I was thinking… You should never need to trigger do_action( ‘wp_ajax…’ ). While I can’t be sure what the issue is, is the code in the question is roughly ok (I think $_POST should be $_GET with .getJSON). Try putting this at the … Read more

how to remove default jquery and add js in footer?

This will do the trick when added to your functions file: if (!is_admin()) add_action(“wp_enqueue_scripts”, “my_jquery_enqueue”, 11); function my_jquery_enqueue() { wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, “//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js”, false, null); wp_enqueue_script(‘jquery’); }