0

On our website we have sections that have different backgrounds that span the full width of the viewport and for this reason we have introduced a custom block called section with its own inner containers etc. This means that when you are editing a page you usually add a section block first before adding the content.

This works fine until you edit a page that doesn't have multiple sections and instead has its wrappers inside the theme template itself. For example a blog post doesn't need to have multiple sections and instead the user just adds the content. This becomes an issue as the editor then has no concept of the wrappers of the single.php template and we can't add them to the styles for the editor because these would then conflict with those for the blocks.

Is it possible to detect when a user is editing a certain post type such as a post? And therefore we can style the editor appropriately?

1 Answer 1

1

Natively, no, not yet. I did find this helper plugin (and your question!) while searching for the same thing though: https://github.com/bigboxwc/wp-editor-page-template-class

Clever JS based solution, it uses the Gutenberg Plugins API and props.selectedTemplate to generate a classname and add it to the editor. You could easily use the code from this plugin in your own theme if desired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.