What is the difference between these two methods of writing $ instead of jQuery in WordPress [closed]

The first is a pattern called a closure. It’s not unique to jQuery. You could just as easily write (function(someVar) { // Inside the closure, someVar == “test” })(“test”); Basically, you’re manually passing jQuery into the closure by referencing the jQuery object externally and aliasing it to $ inside the context of the closure. The … Read more

Using wp_ajax and wp_ajax_nopriv hooks

It depends on what exactly you want to do. If you want to show just a short message, use the same callback for both. But if you need completely different objects and load different additional files depending on the log-in status, use separate callbacks. Basic example, probably not a recommended implementation. 🙂 class Ajax_Controller { … Read more

WordPress Script Loading/Unloading — wp_deregister_script(‘jquery’)

WordPress has essentially two groups of methods to handle scripts, both of which should be used: wp_register_script Registers a script in WordPress. It does not get called, it is just available for WordPress, if it is needed. wp_deregister_script is the exact opposite. It deletes the definitions made in wp_register_script, the script is no longer available … Read more

Add confirmation popup on “Move to Trash”

You can try to admin enqueue this script, with jquery dependency: jQuery( function($) { $(‘.edit-php a.submitdelete, .post-php a.submitdelete’).click( function( event ) { if( ! confirm( ‘Are you sure you want to move the post to trash?’ ) ) { event.preventDefault(); } }); }); where we restrict the conformation on the a.submitdelete clicks to the .edit-php … Read more

wp_enqueue_style built in styles

I’m a little confused by your question, can you not simply use wp_enqueue_style, which you actually wrote into this threads heading(not sure if you know the function exists or not). wp_enqueue_style works in the same way as the wp_enqueue_script counterpart, but of course as you’d expect, enqueues stylesheets.. Here’s a list of the enqueues i … Read more

jQuery plugin function is not a function

I still say this is a jQuery issue; however, it is important to note that WordPress requires no-conflict mode for jQuery. From Codex: jQuery noConflict Wrappers The jQuery library included with WordPress is set to the noConflict() mode (see wp-includes/js/jquery/jquery.js). This is to prevent compatibility problems with other JavaScript libraries that WordPress can link. In … Read more

How to load a jQuery script last?

add_action(‘wp_footer’,’myscript_in_footer’); function myscript_in_footer(){ ?> <script type=”text/javascript”> jQuery(document).ready(function(){ jQuery(“div.domTip_tipBody”).mouseover(function(){ jQuery(“#yyy a.tippy_link”).css(“background-color”,”yellow”);}); jQuery(“div.domTip_tipBody”).mouseout(function(){ jQuery(“#yyy a.tippy_link”).css(“background-color”,”red”); }); }); </script> <?php }

Why is my ajax call refreshing the page?

Try using preventDefault(), it’s a jQuery function for preventing default actions called by the browser. First you should call an event handler by firing up your submitter. You can do this as follow: $(‘#my_upload_form’).submit(function (event) { After catching a submit and giving an event with it, you should prevent the default refresh of a browser: … Read more