Skip to content

Instantly share code, notes, and snippets.

@justintadlock
Created January 10, 2024 16:04
Show Gist options
  • Save justintadlock/d99722f11857f1fd57b8996cce0e3d7b to your computer and use it in GitHub Desktop.
Save justintadlock/d99722f11857f1fd57b8996cce0e3d7b to your computer and use it in GitHub Desktop.
Gets the theme color palette from within a component in the editor (view the console for the palette).
import { registerPlugin } from '@wordpress/plugins';
import { useSetting } from '@wordpress/block-editor';
// Just creating a simple component so that we can use hooks.
registerPlugin( 'jt-log-theme-colors', {
render: () => {
// Use `useSettings()` in WP 6.5.
const palette = useSetting( 'color.palette.theme' );
// View the console to see colors.
// This may be `undefined` when first loading, so you may need
// to do a `undefined !== palette` check in some scenarios.
console.log( palette );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment