• evanltd

    (@evanltd)


    Can anyone explain reasoning behind the new frontend CSS that gets dumped internally into the <head> after updating to 6.5? Specifically stuff like below, which is newly breaking my custom theme layouts. I’m probably being an old confused prude here, but personally I think it’s gross that WP core would print any CSS (other than variables) directly onto the page at all, but these !important flags take it to a new level of pain.

    body .is-layout-constrained > .aligncenter {
        margin-left: auto !important;
        margin-right: auto !important;
    }
    
    body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) {
        max-width: var(--wp--style--global--content-size);
        margin-left: auto !important;
        margin-right: auto !important;
    }

    I guess I don’t understand the logic of demanding that anything not explicitly aligned left, right, or full, MUST have margin: auto. It’s one thing thing to specify that, but why make it !important?

    In my case, I use a lot of group blocks, often nested, to simply function as barebones containers. By default WP appears to give every group block the .is-layout-constrained class. Didn’t cause a problem before, but now in 6.5 everywhere I’ve used a group as a simple container, my desired margin css is overridden with auto !important.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Warren

    (@rabbitwordpress)

    Yes I totally agree, this is utter buffoonery by WordPress 🤷

    Does anyone have a fix for this?

    Thread Starter evanltd

    (@evanltd)

    I dug around looking at some of my other sites, and apparently the global inline css output has had the !important flags for awhile now, at least going back to 6.2. I still maintain that this is really dumb to include !important in default core css, but it’s not the root cause of my problem.

    The problem I’m seeing in 6.5 is that they changed where the “is-layout-constrained” class is applied.

    Previously, it was on the main outer group div. So the CSS in question would then only apply to its immediate child, the inner container. No prob.

    <div class="wp-block-group is-layout-constrained wp-block-group-is-layout-constrained">

    In 6.5 it has moved “is-layout-constrained” to the INNER container.

    <div class="wp-block-group">
       <div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
    

    This means that this sloppy CSS rule now applies to every immediate child element inside a group’s inner container:

    body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) {

    So if I have a heading, an image, whatever, inside a group, it now is forced to have auto left/right margins !important. That’s really gross.

    • This reply was modified 3 months, 4 weeks ago by evanltd.
    • This reply was modified 3 months, 4 weeks ago by evanltd.
    Thread Starter evanltd

    (@evanltd)

    Ok what a rabbit hole this is sending me down! Apparently I missed the boat when WP decided to remove the whole __inner-container div from block output…sorta….sometimes.

    I also missed the boat on theme.json. It appears if your theme does NOT include a theme.json file, WP will continue to output an inner container div inside blocks such as group. A legacy accommodation I guess?

    If your theme DOES include a theme.json file, even if it’s totally blank inside, WP completely changes the html output/structure of blocks, to just a single div with no inner container. Wow.

    Furthermore, if your theme.json includes the appropriate “layout” settings inside it, you then get a new pane in the block editor with a toggle switch [Inner blocks use content width] that looks like it’s meant to replace the functionality of the removed inner container div.

    Whatever legacy fallbacks they had in place prior to 6.5 were obviously working great for me, as I was blissfully unaware of these major block-related changes.

    These fallbacks appear broken in 6.5. Currently I continue to have these “legacy” inner container divs output, but the CSS is now applied to them as if they were the newer simplified “solo” divs.

    This is not easy to fix. All my custom theme CSS—across 20+ sites—is built to target the inner containers.

    Thread Starter evanltd

    (@evanltd)

    Ok, with more research I’ve concluded that even though I actually love the Gutenberg editor itself, clearly this push toward “block themes” and “full site editing” is not for me. After nearly 20yrs of using WP as a CMS rather than a pagebuilder, writing custom PHP and CSS and enjoying the separation of content and design, it’s hard to wrap my head around how visually click-designing an entire website in the block editor would ever be faster, easier, less aggravating—or even possible given the amount of customization we put into our sites.

    Guess I’m stuck being a dinosaur for now, which means not creating a theme.json, and disabling new features as they arrive. Here are two ways to disable the global inline css output. Both seem to work for me. I’m not sure which approach is more proper.

    function remove_global_styles_and_svg_filters() {
    	remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
    	 remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
    }
     add_action('init', 'remove_global_styles_and_svg_filters');

    OR:

    function remove_global_styles(){
        wp_dequeue_style( 'global-styles' );
    }
    
    add_action( 'wp_enqueue_scripts', 'remove_global_styles' );
    MarcGuay

    (@marcguay)

    Another way:

    add_theme_support( 'disable-layout-styles' )

    ref: https://make.wordpress.org/core/2022/10/10/updated-editor-layout-support-in-6-1-after-refactor/

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.