Skip to content

Instantly share code, notes, and snippets.

@slushman
Last active September 23, 2023 13:03
Show Gist options
  • Star 40 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save slushman/6f08885853d4a7ef31ebceafd9e0c180 to your computer and use it in GitHub Desktop.
Save slushman/6f08885853d4a7ef31ebceafd9e0c180 to your computer and use it in GitHub Desktop.
How to link into the WordPress Customizer
@dbmpls
Copy link

dbmpls commented Sep 11, 2020

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