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’, get_stylesheet_directory_uri() . ‘/js/testscript.js’, array(‘jquery’), ”, true); wp_localize_script( ‘testpage’, ‘testpage_obj’, array( ‘json_data’ => get_stylesheet_directory_uri() . ‘/js/mydata.json’ ) ); wp_enqueue_script(‘testpage’); In the JS file jQuery.getJSON(testpage_obj.json_data)

How to prevent wordpress from loading old versions of jquery in wp_head();?

add_action(‘wp_enqueue_scripts’, ‘no_more_jquery’); function no_more_jquery(){ wp_deregister_script(‘jquery’); } That will deregister jquery. But why wouldn’t you want jQuery at all? If you mean to simply use your own, you should do it in that function, like this: add_action(‘wp_enqueue_scripts’, ‘no_more_jquery’); function no_more_jquery(){ wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, “http” . ($_SERVER[‘SERVER_PORT’] == 443 ? “s” : “”) . “://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js”, false, null); wp_enqueue_script(‘jquery’); … Read more

How to control what jQuery version to include, with wp_enqueue_script

That’s the size of the minified jQuery nowadays 🙂 You can load the latest from Google: wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, (“http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js”), false, ‘1.8.2’); Please keep in mind that this can cause issues moving forward, as you are forcing WordPress to load a certain version of jQuery instead of the version bundled with it. There are plugins out … Read more

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 missing info in this respect. This is how I would get on about this: In your functions.php file or similar: add_action(wp_ajax_handle_login, ‘handle_login_ajax’); add_action(wp_ajax_nopriv_handle_login, ‘handle_login_ajax’); Make sure your … Read more

How to get attachment id as soon as it is uploaded through media uploader in jquery?

You are close, you just need to hook into the add event instead of the reset event. (In case you did not know, these are standard events provided by Backbone collections. So familiarizing yourself with that will be helpful when developing things around stuff where WordPress employs Backbone.js.) So basically you’d modify your code like … Read more

What is the simplest ajax upload plugin or script to be used with wordpress?

I have used the native uploader with great results. Try adding this snippet of JS: jQuery(‘#upload_image_button’).click(function() { formfield = jQuery(‘#fwpPhoto’).attr(‘name’); tb_show(”, ‘media-upload.php?type=image&amp;TB_iframe=true’); return false; }); window.send_to_editor = function(html) { imgurl = jQuery(‘img’,html).attr(‘src’); jQuery(‘#fwpPhoto’).val(imgurl); tb_remove(); } Then, in your HTML: <input id=”fwpPhoto” name=”facultyPhoto” value=””> <input id=”upload_image_button” type=”button” value=”Upload Image”> For Multiple Uploaders <input id=”facultyPhoto-1″ name=”facultyPhoto-1″ value=”” … Read more