How to overwrite a JavaScript core function?

You can’t. While manipulation of JS and HTML is possible, it is not adviceable as a long term strategy unless it was explicitly document as “the right way” in the codex, code comment, or some other core document. In addition to the theoretical objection, right now it is hard or almost impossible to override specific … Read more

Lightbox popup on WooCommerce add_to_cart action

The following works for me for product archive pages (these include both the main shop page as well as archive pages for product categories, for example). It will show the current cart contents in a thickbox. I chose to show this for this example just because that’s the data that one gets back through Ajax … Read more

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 deserializes the GET querystring from the URL, and the request body for POST requests before populating PHP’s request variables. Your code functioned as expected when data consisted solely of … Read more

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 from the server: ‘ + response); console.log(response); }); And your PHP in functions.php //Called by Ajax from App – list the contents of the folder so they can be … Read more

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