How do I implement selective refresh with a customizer setting?

Create a function to output the selectively refreshed template code (I wrapped the HTML within <div class=”cta-wrap”> to make it easier to target this particular block of markup.) function wpse247234_cta_block() { if ( ( get_theme_mod( ‘intro_page’ ) ) != ” ) { $intro_id = get_theme_mod( ‘intro_page’ ); $intro_header = get_the_title( $intro_id ); $intro_excerpt = get_the_excerpt( … Read more

Customizer JS API

1) Maybe bind to the api.ready state which may fix having to call your section twice (function($, api){ api.bind( ‘ready’, function() {… } })(jQuery); I saw a note in trac that said “Note that the APIs for dynamically-added controls, and APIs for JS-templated custom Sections and Panels are not yet available as of WordPress 4.2. … Read more

Add settings to menu items in the Customizer

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 comment: // @todo Add get_post_metadata filters for plugins to add their data. Nevertheless, even though we didn’t implemented core support for previewing changes to nav menu item postmeta, it … Read more

How do I implement the WordPress Iris picker into my plugin on the front-end?

This drove me mad for a while, but I got it to work by adding them with the full arguments that are used in the admin script loader rather than just referencing the handle. When I print the $wp_scripts global on the front end, iris and wp-color-picker are nowhere to be found, though all of … Read more

Link to specific Customizer section

As you’ve already discovered, links to the customizer always start with /wp-admin/customize.php. Append ?autofocus[section] =section_name to checkout your section within the customizer. Both parameters (section and section_name) are registered within your customize_register hook: $wp_customize->add_section If you can’t find the hook, check the HTML markup of the customizer for further information. Both parameters are included within … Read more

New WP_Customize API – how does it work under the hood?

There’s a few bits here that apply, but the short of it is this code in customize-preview.js: this.body.on( ‘click.preview’, ‘a’, function( event ) { event.preventDefault(); self.send( ‘scroll’, 0 ); self.send( ‘url’, $(this).prop(‘href’) ); }); The event.preventDefault prevents the links from actually working. The following code then sends a message back upwards telling it to a) … Read more

get_option() vs get_theme_mod(): Why is one slower?

The answer that yes, the theme_mod functions will be slower, but not significantly, and the benefits outweigh the differences. Theme mods are stored as options. So, in essence, the theme_mod functions are wrappers around the options functions. First, understand that theme_mod settings are stored as an array in a single option, keyed to the specific … Read more