Link to Customizer Sections

One neat “feature” introduced in WordPress 4.1 was the removal of the background and header admin screens in favor of the customizer (see ticket). Now if you click to customize one of those items, it links directly to the customizer and opens the appropriate panel.

If your plugin or theme adds customizer options, you can also link to those. Just use:

admin_url( 'customize.php?autofocus[control]=control-name' )

Replace “control-name” with the name of the control you’d like to link to.

Examples

For a new theme I’m building, users need to select pages to use in order to display them on a specific page template.

If they haven’t selected any pages, I display this notice (only for logged in users who have the ability to customize):

<?php if ( current_user_can( 'customize' ) ) { ?>
	<div class="admin-msg">
		<p><?php _e( 'There are no pages available to display.', 'textdomain' ); ?></p>
		<p><?php printf(
			__( 'These pages can be set in the <a href="%s">customizer</a>.', 'textdomain' ),
			admin_url( 'customize.php?autofocus[control]=showcase-tag' )
		); ?></p>
	</div>
<?php }

You can also see how this the background and header links are done in core:
https://core.trac.wordpress.org/ticket/25569

About Devin

I am a developer based in Austin, Texas. I run a little theme shop called DevPress and help manage a WooCommerce shop with Universal Yums. Find me on twitter @devinsays.

2 Responses

  1. Virgo

    Hi Davin,
    awesome explanation of this new awesome feature.
    But users needs to change the autofocus[control] in autofocus[section] or autofocus[panel] depends on the control type.
    This is not so clear in the snippet above.

  2. Do you know if it’s possible to link to another panel/section/control in Customizer without reloading the page? For instance, a link in a custom control that would redirect you to a control defined by core.

Leave a Reply to Virgo Cancel reply