How to pass aa JS variable to PHP?

Step 1: Run wp_localize_script, add below function in function.php add_action( ‘wp_enqueue_scripts’, ‘jsto_php_enqueue_scripts’, 5 ); public function jsto_php_enqueue_scripts() { wp_register_script( ‘file_handle’, plugin_dir_url( __FILE__ ) . ‘js/js-file-name.js’, array( ‘jquery’ ), ‘0.0.1’, false ); wp_enqueue_script(‘file_handle’); // Set Nonce Values so that the ajax calls are secure $add_something_nonce = wp_create_nonce( “add_something” ); $ajax_url = admin_url( ‘admin-ajax.php’ ); $user_id = … Read more

Time consuming callbacks in customizer

Building upon How to hook on customizer section expanded/active/opened event? question, perhaps you could listen for the section (or panel) expanding like this to unbind functions from the previuos section and bind them to the current section. (function ( api ) { // Wait for Customizer to be ready api.bind( ‘ready’, function() { // “cache” … Read more

Enqueue scripts all over but not in single.php

with is_singular() if (!is_singular(‘post’)) { function live_search() { wp_enqueue_script(‘live_search’, get_bloginfo(‘stylesheet_directory’) .’/assets/js/live.search.js’, array(‘jquery’), ‘1.0.1’, true ); wp_localize_script( ‘live_search’, ‘MovieWordpressSearch’, array( ‘api’ => moviewp_url_search(), ‘nonce’ => moviewp_create_nonce(‘moviewp-search-nonce’), ‘area’ => “.live-search”, ‘more’ => “Show all”, ) ); } add_action(‘wp_enqueue_scripts’, ‘live_search’); }