Skip to content

Instantly share code, notes, and snippets.

@mintbird
Last active July 25, 2023 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mintbird/c449fbde002891129746afdb70d836eb to your computer and use it in GitHub Desktop.
Save mintbird/c449fbde002891129746afdb70d836eb to your computer and use it in GitHub Desktop.
WordPress / Gutenberg Snippets

Retrieve global styles (theme.json)

wp.data.select("core").__experimentalGetCurrentThemeBaseGlobalStyles();

Retrieve theme.json

WP_Theme_JSON_Resolver::get_theme_data();

Filter theme.json

Reference

function filter_theme_json_theme( $theme_json ){
	$new_data = array(
		'version'  => 2,
		'settings' => array(
			'color' => array(
				'text'       => false,
				'palette'    => array( /* New palette */
					array(
						'slug'  => 'base',
						'color' => 'white',
						'name'  => __( 'Base', 'theme-domain' ),
					),
					array(
						'slug'  => 'contrast',
						'color' => 'black',
						'name'  => __( 'Contrast', 'theme-domain' ),
					),
				),
			),
		),
	);

	return $theme_json->update_with( $new_data );
}
add_filter( 'wp_theme_json_data_theme', 'filter_theme_json_theme' );

Get all global style variations

WP_Theme_JSON_Resolver::get_style_variations()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment