• Resolved iSaumya

    (@isaumya)


    I got a question for which I can’t find an answer anywhere on the internet.
    In my theme’s after_setup_theme action I have added the following lines to tweak the editor style a little bit:

    add_theme_support( 'editor-styles' );
    add_editor_style( 'assets/css/block-editor/editor-style.css' );

    Now the crazy thing is that in that CSS file in I add like:

    .wp-block {
      max-width: 726px;
    }

    That works fine and I can see that happening. But if I try to do conditional styling based on post type like this:

    body.post-type-page .editor-styles-wrapper .wp-block,
    body.post-type-notices .editor-styles-wrapper .wp-block {
      max-width: 1100px;
    }
    body.post-type-post .editor-styles-wrapper .wp-block {
      max-width: 726px;
    }

    This does not work. I don’t know why. WP Admin Simply doesn’t pick up the conditional style beside setting up global style. Does anyone know how can I do conditional styling in the editor-style.css?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    WP prepends .editor-styles-wrapper selector to any of your editor styles, so if your selector includes anything above that element the selector as implemented is invalid and ignored. If you want to select based on elements above .editor-styles-wrapper you probably need to implement it as an admin style instead of editor style.

    If the rules you want are brief, you could output an inline style block containing your rules from the “admin_print_styles” action.

    Thread Starter iSaumya

    (@isaumya)

    Hi @bcworkz,
    Thanks a lot for clearing the doubt.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Editor styles based on post type is not picking up by wp-admin’ is closed to new replies.