Created
January 10, 2024 16:04
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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