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.

  • 2
    What editor are you referring to? Jun 7 at 13:25

You 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');
  • This is exactly what I was looking for - awesome. Thank you Phil! Jun 17 at 15:10

The html code must be prepared for it.
For example different classes for the use of css.


<div class="pages">
  <a href="#">title</a>
  <?php whatever the page title code ?>
<div class="posts">
  <a href="#">title</a>
  <?php whatever the posts title code ?>

then the css is easy:

  • 1
    That is obvious. But how do you set the class depending on what is displayed in the first place? That is actually the question. Jun 8 at 9:00
  • show the code, then we can look for a way. or editing html, or doing some javascript to change css Jun 8 at 18:44
  • that is possible to achieve with javascript Jun 8 at 19:29
  • The code is just the initial Wordpress setup as you can download it on the website. I want to know how I can add a class in the editor (as you described in your answer) , such that I know whether I am in a post or page Jun 10 at 7:35
  • got it, sorry I only know coding it. Jun 11 at 3:56

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.