How to manage ajax calls and JSON in wordpress

Ajax Handler It is indeed a bit confusing that the Ajax handler is in the wp-admin/ directory, but yes, you can and should use it for non-admin requests too. You then register a handler for the wp_ajax_nopriv_[action] hook, instead of the normal wp_ajax_[action]. In this case you only have to follow the first lines of … Read more

How do I make script load after jquery?

You have a typo in your code. It should be: function load_my_script(){ wp_register_script( ‘my_script’, get_template_directory_uri() . ‘/js/myscript.js’, array( ‘jquery’ ) ); wp_enqueue_script( ‘my_script’ ); } add_action(‘wp_enqueue_scripts’, ‘load_my_script’); The jQuery dependency needs to be an array(), not just a string. This will force your script to load after jQuery.

Is jQuery included in WordPress by default?

Yes, jQuery is part of WordPress core. But–it can become outdated, because jQuery updates can happen in between WP releases. The recent release of WordPress does use a very recent version of jQuery. By default, wp_enqueue_script(‘jquery’) grabs jQuery from the core at /wp-includes/js/jquery/jquery.js. The “correct” way to add jQuery to your WP site is: function … Read more

Using WordPress 3.5 Media Uploader in meta box?

To get you started, the basic functions and overrides as far as I know currently.There might be better solutions, but I only had two days with 3.5 yet: // open modal – bind this to your button if ( typeof wp !== ‘undefined’ && wp.media && wp.media.editor ) wp.media.editor.open( ##unique_id_here## ); // backup of original … Read more

How to save the state of a drag and drop jQuery UI Sortables front end layout editor?

Brady is correct that the best way to handle saving and displaying of custom post type orders is by using the menu_order property Here’s the jquery to make the list sortable and to pass the data via ajax to wordpress: jQuery(document).ready(function($) { var itemList = $(‘#sortable’); itemList.sortable({ update: function(event, ui) { $(‘#loading-animation’).show(); // Show the … Read more

I want to enqueue a .js file to my child theme

Here’s a working example: add_action( ‘wp_enqueue_scripts’, ‘menu_scripts’ ); function menu_scripts() { wp_enqueue_script( ‘responsive-menu’, get_bloginfo( ‘stylesheet_directory’ ) . ‘/js/responsive-menu.js’, array( ‘jquery’ ), ‘1.0.0’ ); wp_enqueue_script( ‘custom-script’, get_stylesheet_directory_uri() . ‘/js/custom_script.js’, array( ‘jquery’ ) ); } Or like this which apparently loads faster: function my_scripts_method() { wp_enqueue_script( ‘custom-script’, get_stylesheet_directory_uri() . ‘/js/custom_script.js’, array( ‘jquery’ ) ); } add_action( ‘wp_enqueue_scripts’, … Read more

Is this Solution for Caches vs Cookies Going to Get Me in Trouble?

Your solution with comment_author_proxyhash cookie will of course technically work – all caching plugins I know doesn’t analyze hash value and will just stop delivery of cached content based on comment_author_* cookie presense. Problem here is that page caching functionality is something websites really need and often page caching is configured exactly because naked WordPress … Read more

How to correctly include jquery-ui effects on wordpress

While WordPress does include the jQuery UI libraries, it does not include the UI/Effects library. That library is separate and standalone. You’ll need to include a copy of the effects.core.js file and enqueue it separately. Note that you should name it jquery-effects-core when en-queuing it, for naming consistency. You can include it like this: wp_enqueue_script(“jquery-effects-core”,’http://example.com/whatever/effects.core.js’, … Read more

Enqueue core jQuery in the footer?

To do that you will first have to deregister your jQuery script and then register again. If you use jQuery comes with WordPress then following is the function your are looking for. function starter_scripts() { wp_deregister_script( ‘jquery’ ); wp_register_script( ‘jquery’, includes_url( ‘/js/jquery/jquery.js’ ), false, NULL, true ); wp_enqueue_script( ‘jquery’ ); wp_enqueue_style( ‘starter-style’, get_stylesheet_uri() ); wp_enqueue_script( … Read more