Created
December 5, 2024 16:43
-
-
Save fabiankaegy/abb054d09334b23edd3cd2ec25df7b55 to your computer and use it in GitHub Desktop.
Set default rendering mode in WordPress 6.6+
This file contains hidden or 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 { useDispatch, useSelect } from '@wordpress/data'; | |
import { useEffect } from '@wordpress/element'; | |
import { store as editorStore } from '@wordpress/editor'; | |
// Define post types that show the full template locked site editor by default. | |
const TEMPLATE_LOCKED_POST_TYPES = ['page', 'post']; | |
registerPlugin('namespace-set-default-template-rendering-mode', { | |
render: function Edit() { | |
const { setRenderingMode } = useDispatch(editorStore); | |
const [postType] = useSelect((select) => [select(editorStore).getCurrentPostType()], []); | |
useEffect(() => { | |
if (!TEMPLATE_LOCKED_POST_TYPES.includes(postType)) { | |
return; | |
} | |
setRenderingMode('template-locked'); | |
}, [setRenderingMode, postType]); | |
return null; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment