I created a Wordpress theme and now I am working on an editor-stylesheet for the block editor to better reflect the look of the theme in the editor. For this, I need to be able to address different post types in there.
For the frontend, there is the body_class()
function to be used in templates, 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.
Now, the post-type class is in the body tag of the page, also in edit mode, but apparently the editor-stylesheet CSS is applied in a kind of "isolated" way – combined selectors which contain 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.
Any ideas how to do that?
BTW, I also tried to check the post-type using Javascript/jQuery:
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. (?)
Addition: Trying everything I can think of to find a workaround solution, I also tried this script to just see if I can check for body classes at all when I am using the editor:
jQuery(document).ready(function() {
if(jQuery('body').hasClass('post-type-page')) {
alert("It's a page!");
} else {
alert("It's not a page");
}
});
The result on editor pages (i.e. the web page displaying the WP block editor): No alert at all! Why that??? Does the block editor Javascript block/prevent all other Javascript?
P.S.: I posted the first part of this question on StackExchange WordPress development before, but got no reactions at all, so i am trying it here...
"It's a page!"
Can you edit your post to show us how you're queuing the scripts and styles you want to appear on the admin page edit screens? – Atlasfunctions.php
file, and the CSS I am talking about is in the stylesheet I defined as editor stylesheet for the block editor (which otherwise works fine) – Alamoadmin_enqueue_scripts
hook, because scripts loaded for a site's front end are not generally loaded on the back-end admin side. – Atlas