Skip to content

Instantly share code, notes, and snippets.

@slushman
Last active October 9, 2024 00:34
Show Gist options
  • Select an option

  • Save slushman/6f08885853d4a7ef31ebceafd9e0c180 to your computer and use it in GitHub Desktop.

Select an option

Save slushman/6f08885853d4a7ef31ebceafd9e0c180 to your computer and use it in GitHub Desktop.
How to link into the WordPress Customizer
@cliffordp

Copy link
Copy Markdown

Very nice! I found it from https://www.slushman.com/how-to-link-to-the-customizer/

Heads up: These do not work if the Customizer is active, giving the link a .customize-unpreviewable class and therefore gets this CSS applied: cursor: not-allowed !important;

You can use https://developer.wordpress.org/reference/functions/is_customize_preview/ to detect if in the customizer.

And https://developer.wordpress.org/themes/customize-api/tools-for-improved-user-experience/#selective-refresh-fast-accurate-updates may be a handy alternative or supplement, too.

@maxviewup

Copy link
Copy Markdown

TIP: if you want to add links inside the customizer, you can use the customizer API:
<a href="javascript:wp.customize.panel( 'widgets' ).focus();">Widgets Panel</a>

@dbmpls

dbmpls commented Sep 11, 2020 •

Copy link
Copy Markdown

Turned panel, section and control into shortcode options which you can easily stick into custom widgets or other help text on your site dashboard:

function customizer_link_shortcode($atts, $content = null){
		//type: panel, section, control
		//name: name of panel, section or control
		//link_text: the link title or name
		extract(shortcode_atts(array('type' => 'panel', 'name' => 'nav_menus', 'link_text' => 'Edit Menu'), $atts));
		
		switch($type){
			case "panel":
				$query['autofocus[panel]'] = $name;
				$url = add_query_arg( $query, admin_url( 'customize.php' ) );
				break;
				
			case "section":
				$query['autofocus[section]'] = $name;
				$url = add_query_arg( $query, admin_url( 'customize.php' ) );
				break;
			
			case "control":
				$query['autofocus[control]'] = $name;
				$url = add_query_arg( $query, admin_url( 'customize.php' ) );
				break;		
		}
		
		$link = sprintf('<a class="customizer_link" href="%1$s">%2$s</a>',$url,$link_text);
		
		return $link;
		
	}
add_shortcode( 'customizer_link', ,'customizer_link_shortcode' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment