Localize variable for multiple Shortcodes

Your ploblem is that wp_localize_script print to the html markup a javascript object similar to: var slider = {“id”:”a_unique_id_here”}; if you call it more times, e.g. using more shortcodes in same page, whati is printend in html markup is var slider = {“id”:”a_unique_id_here”}; var slider = {“id”:”another_unique_id_here”}; var slider = {“id”:”third_unique_id_here”}; so you are overwriting … Read more

How to stop loading multiple copies of jquery

You should remove these lines from your header.php <script language=”javascript” type=”text/javascript” src=”https://wordpress.stackexchange.com/questions/154191/<?php bloginfo(“template_url’); ?>/javascripts/jquery.js”></script> <script language=”javascript” type=”text/javascript” src=”https://wordpress.stackexchange.com/questions/154191/<?php bloginfo(“template_url’); ?>/javascripts/tabber.js”></script> <script language=”javascript” type=”text/javascript” src=”https://wordpress.stackexchange.com/questions/154191/<?php bloginfo(“template_url’); ?>/javascripts/superfish.js”></script> And instead add the following function in your functions php… right at the top. wp_enqueue_script function sg_theme_js(){ wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘tabberjs’, get_template_directory_uri().’/javascripts/tabber.js’, array(‘jquery’), 1.0, true); wp_enqueue_script( ‘superfishjs’, get_template_directory_uri().’/javascripts/superfish.js’, … Read more

possible to make sections in theme customizer sortable and saveable at publish button clicked?

Simple tutorial – How to sort customizer sections in the panel and add order to theme. 1. You must use prefixes to do this because customizer don’t support custom classes. ctmss_panel_ – for panels ctmss_section_ – for sections ctmss_hidden_ – for hidden sections that has a input with values 2. Add panel to the Customizer … Read more

Widget “Save” resetting jQuery hidden fields

You’re looking for jQuery.live(), or jQuery’s livequery plugin, depending on what you’re seeking to do. (The second is the proper one if you need to use onChange events.) As things stand, your jQuery hooks are not called when the save button is called, because the form’s tags are reloaded using ajax, and jQuery(document).ready() is, obviously, … Read more

Best approach for loading a sidebar Only if the screen max-width is >900px?

On my website I load the recent comments per AJAX for window sizes above 480px: if ( 480 < jQuery(window).width() ) { jQuery(document).ready( function() { jQuery.get(‘http://toscho.de/?rc’, function(data) { jQuery(data).insertBefore(‘#inner’); } ); } ); jQuery(‘#posts’).after(‘<div class=clear>&#160;</div>’); } This code is quite old and not very elegant. But it may give you a hint for the right … Read more

How to use WordPress (PHP) functions in AngularJS partials files?

What works is calling WP’s Ajax endpoint. Note that it is not the address of your partial, but the fixed WP address for all AJAX calls wp_localize_script(‘handle’, ‘myLocalized’, array( ‘ajaxUrl’ => admin_url( ‘admin-ajax.php’ ) ) ); provides the endpoint adress in the JS object myLocalized. You send all requests to that page and refer to … Read more

Unbind postbox click handler

You can just put the necessary javascript in a file and enqueue it on the necessary page: add_action( ‘admin_enqueue_scripts’, ‘add_admin_scripts’, 10, 1 ); function add_admin_scripts( $hook ) { //You can globalise $post here and enqueue the script for only certain post-types. if ( $hook == ‘post-new.php’ || $hook == ‘post.php’) { wp_register_script( ‘my_js_handle’,’/path/to/js/my-js-file.js’,array(‘jquery’),1,true); wp_enqueue_script(‘my_js_handle’); } … Read more