admin管理员组文章数量:1291229
I have different styles applied to pages (I hide the title for them) and posts (I don't want to hide the title here, but style the date of the post). I want to style them differently, which ist possible on the site itself. But in the editor I don't seem to have the possibility to distinguish between pages and posts.
There is no css-class in an upper element which indicates whether I am editing a page or a post which I could use in my css.
How can i know what I am editing in the editor - a page or a post. It's driving me crazy - there must be a way to know this.
I have different styles applied to pages (I hide the title for them) and posts (I don't want to hide the title here, but style the date of the post). I want to style them differently, which ist possible on the site itself. But in the editor I don't seem to have the possibility to distinguish between pages and posts.
There is no css-class in an upper element which indicates whether I am editing a page or a post which I could use in my css.
How can i know what I am editing in the editor - a page or a post. It's driving me crazy - there must be a way to know this.
Share Improve this question asked Jun 7, 2021 at 13:18 Mathias BaderMathias Bader 1357 bronze badges 1- 2 What editor are you referring to? – Jacob Peattie Commented Jun 7, 2021 at 13:25
2 Answers
Reset to default 2You can use the admin_body_class
hook to add your own CSS classes. For example (if you're using Gutenberg):
function pb_admin_body_class($classes) {
$screen = get_current_screen();
if (!$screen->is_block_editor()) {
return $classes;
}
$post_id = isset($_GET['post']) ? intval($_GET['post']) : false;
$post_type = get_post_type($post_id);
if ($post_type) {
$classes .= $post_type;
}
return $classes;
}
add_filter('admin_body_class', 'pb_admin_body_class');
The html code must be prepared for it.
For example different classes for the use of css.
example:
<div class="pages">
<a href="#">title</a>
<?php whatever the page title code ?>
</div>
<div class="posts">
<a href="#">title</a>
<?php whatever the posts title code ?>
</div>
then the css is easy:
.pages{display:none;}
本文标签: block editorHow to know whether you are editing a page or a post
版权声明:本文标题:block editor - How to know whether you are editing a page or a post? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505213a2382280.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论