Weston Ruter
  • Member for 10 years, 4 months
  • Last seen more than a month ago
Is it possible to use wp_localize_script to create global JS variables without a specific script handle?
14 votes

You can export any data you want in the wp_head hook, as the answers above show. However, you should use json_encode to prepare the PHP data for exporting to JS instead of trying to embed raw values ...

View answer
Add button to Customizer
Accepted answer
7 votes

There are three things you need to do in particular. As there are no settings associated with the control, you need to explicitly supply an empty array for settings, as otherwise it will try to look ...

View answer
Add settings to menu items in the Customizer
Accepted answer
6 votes

You're running up against an incomplete implementation of modifying nav menus in the Customizer. In particular, inside of the phpdoc for WP_Customize_Nav_Menu_Item_Setting::preview() you can see this ...

View answer
Where to get the unsaved list of widgets in customizer?
Accepted answer
6 votes

You can get the list of widgets in a sidebar via: wp.customize('sidebars_widgets[sidebar-1]').get() This is a list of the widgets' IDs. The sidebars_widgets[sidebar-1] is the setting ID for the ...

View answer
Customizer - instantiating settings and controls via javascript
Accepted answer
6 votes

If you register your settings on the server then you do not need to register them on the client in JS, as this will be done for you. Here are some examples creating controls after you have created the ...

View answer
WordPress Customizer: How can you have multiple active callbacks on one control?
Accepted answer
6 votes

You can create a third active callback function that just references the two existing ones, for example via an anonymous function (PHP≥5.3): // About Block Button Text $wp_customize->add_setting( '...

View answer
How to remove menus section from WordPress theme customizer
6 votes

The correct way to disable nav menus in the customizer is via the customize_loaded_components filter as documented on its hook reference page: /** * Removes the core 'Menus' panel from the ...

View answer
How to mix partial and full page refresh in the same section of the customizer?
Accepted answer
6 votes

tl;dr See standalone example plugin that demonstrates initiating a full refresh when a selective refresh request enqueues different scripts or styles and also which re-initializes JS behaviors for ...

View answer
Get entered value of customiser field for live preview
Accepted answer
6 votes

Yes. wp.customize( 'header_textcolor' )(): ( function( $ ) { //Update site background color... wp.customize( 'background_color', function( value ) { value.bind( function( newval ) { ...

View answer
How to open the 404 page in the Theme Customizer preview?
Accepted answer
5 votes

Cool use case. Without any code, in order to load the 404 template, all you have to do is navigate to a non-existent URL on your site. Then, while being logged-in, click the Customize link in the ...

View answer
Customiser `active_callback` not working on control with `postMessage` transport method
Accepted answer
5 votes

Because postMessage uses JavaScript entirely, any PHP active_callback will not get called unless the preview refreshes (e.g. via wp.customize.previewer.refresh()). So what you need to do is implement ...

View answer
Passing data from customize-controls.js to the customize-preview.js
Accepted answer
4 votes

Customizer Message Passing What follows are some snippets that show the required order of operations for getting the message-passing handshakes to work. In your example code, the control is sending ...

View answer
Using string instead of object class instantiation on the walker argument breaks wp_nav_menu
Accepted answer
4 votes

Apparently custom nav menu walkers are not supported though they were supposed to be. I'm surprised this only has been discovered now. However, there is an easy fix for you to get them to work. Just ...

View answer
wp.customize.bind ready event not fired
4 votes

Do not put the Customizer ready event handler inside of the jQuery event handler. The Customizer ready will trigger at jQuery ready, so you are adding the event handler too late. Just do: wp....

View answer
How to make get_theme_mod work with AJAX in the customizer preview
Accepted answer
4 votes

There is a bug in WordPress 4.8.2 which causes pending customized changes to not be injected into Ajax requests in the preview. This has been fixed in 4.9-alpha via #42162. In the mean time, however, ...

View answer
site identity section name?
Accepted answer
4 votes

The “Site Identity” section has the ID of title_tagline for historical reasons. If you want to see the IDs for the core sections, all you have to do is look at the source for WP_Customize_Manager::...

View answer
Set Default Page On Customizer Live Preview
Accepted answer
4 votes

The default URL being previewed is home_url( '/' ). When no url query parameter is present when opening customize.php, this is the preview URL that is used. You can override the previewed URL when ...

View answer
Customizer - loading settings/controls/sections/panels based on a id/page id
Accepted answer
4 votes

The most robust way to do this is to do JavaScript-based instantiation of the sections, controls, and settings dynamically in response to the URL being previewed. Since you can navigate around the ...

View answer
Disable Visible Edit Shortcuts in the Customizer
4 votes

The simplest way to disable edit shortcuts without unwanted side effects is to no-op override the JS function that generates them in the first place. You can do this from PHP as follows: add_action( '...

View answer
Access Customizer's DOM - jQuery
Accepted answer
4 votes

The customizer preview is in a different window than the window that contains the customizer controls. Specifically, the customizer preview is contained inside of an iframe. So that is why you cannot ...

View answer
Customizer JS API dynamically add sections and controls
Accepted answer
4 votes

What you are looking for here is already 80% available already, if you use the Customize Posts plugin and enable the Testimonials content type in Jetpack. Sections for testimonial posts can be listed ...

View answer
Load page in customizer preview on panel click?
Accepted answer
3 votes

I've documented how to do this in my post Navigating to a URL in the Customizer Preview when a Section is Expanded, though naturally you'd just use panels instead of sections. This should get you ...

View answer
Customizer JS API: Adding a "dropdown-pages" control
Accepted answer
3 votes

You're right, that doesn't work… yet. We didn't add support for the dropdown-pages control in #30738 because we wanted to leverage the REST API for this control to fetch the pages. So in 4.9 this is ...

View answer
Is it possible to conditionally displaying and hiding of customizer controls for each device preview?
3 votes

I'm not familiar working with Kikri, but I've made a standalone example plugin that shows the approach I'd use to get controls to be contextual based on the previewed device. The plugin adds colored ...

View answer
How to make a Customizer partial force full refresh instantly?
3 votes

If you always want a page refresh, then all you have to do is simply remove this line: $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; Or explicitly set it to refresh: $...

View answer
How to suppress anchor tag click redirection in customizer preview frame?
Accepted answer
3 votes

Update: The fix here has been incorporated into WordPress Core trunk for the upcoming 4.5 release (now in alpha). See r36371. I think the problem with the unbinding of the event handler is that it is ...

View answer
How to access the nav_menus panel with the customizer api?
3 votes

The Nav Menus panel is added at customize_register action priority 11, so you need to set the priority at priority 12 (or above). This works for me: <?php add_action( 'customize_register', ...

View answer
WP Cron is "half-failing" to insert posts
3 votes

I just encountered this very same problem. I was trying to do wp_insert_post() from within a cron action, and the script would apparently just die during some save_post action handler. I tracked down ...

View answer
Customizer JS API: Adding Setting Dynamically Not Working
Accepted answer
2 votes

When you register the setting in JS, you need to supply the current value saved in the DB as the value, not some default value. So instead of: var setting = new api.Setting( 'mySetting', 'JS Default ...

View answer
Setting dirty on customizer
Accepted answer
2 votes

Just set the saved state to false: wp.customize.bind( 'ready', function() { wp.customize.state( 'saved' ).set( false ); } );

View answer