I am working on an editor-stylesheet for the block editor to better reflect the layout of my theme in the editor, and I need to be able to address different post types in there.
In the frontend, there is the body_class()
function, which inserts - among others - a class which identifies the post-type and can be used in combined selectors to adress certain elements only in a particular post-type.
The post-type class is there in the body
tag of the page which displays the editor, but apparently the editor CSS from the stylesheet is applied in a kind of "isolated" way – combined selectors including classes that are in the body
tag won't work in the editor.
So I am looking for something similar which would work in the block editor, so that I can use it in combined selectors which only apply to certain elements in a particular post-type.
Addition:
I tried to check the post-type this way:
wp.domReady(function() {
var postType = jQuery('form.metabox-base-form input#post_type').attr('value');
if(postType == 'post'){
alert("It's a post!");//in real life some other action...
}
});
But although it would be logical to at least trigger the alert I put in there, nothing happens when I load the edit page of a post, where that input element including its "post" value is clearly present. (?)