• Resolved pracko

    (@pracko)


    How can I swap the order of GenerateBlocks Inline Embedded CSS (generateblocks-css) and the CSS created in my Simple CSS plugin (simple-css-output)?

    Right now, GenerateBlocks’ CSS is printed first, and Simple CSS’s CSS is printed second. I want the GB CSS to come last so that individual block customizations will override any conflicting CSS from SCSS.

    This is the order I would like to load my stylesheets in:

    1. Theme’s (Neve) CSS
    2. WP Customizer CSS
    3. Simple CSS plugin CSS
    4. GenerateBlocks plugin CSS

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Tom

    (@edge22)

    Hi there,

    You could tell Simple CSS to load earlier:

    add_action( 'wp', function() {
        remove_action( 'wp_head', 'simple_css_generate' );
        add_action( 'wp_head', 'simple_css_generate', 9 );
    } );

    Let me know if that helps or not ??

    Thread Starter pracko

    (@pracko)

    Hi Tom, that works to make Simple CSS load earlier, but GenerateBlocks CSS still comes before and I need the GB CSS to come last. Is there an action I can use for GB to do that?

    Thread Starter pracko

    (@pracko)

    FWIW, I was able to use the following to put everything in the proper order except for Simple CSS because SCSS prints the CSS output inline and I can’t re-order it using this method:

    function swp_reorderstylesheets() {
      global $wp_styles;
     
      $keys=[
        'theme-css'
        'generateblocks',
      ];
      $wp_styles->queue = array_values($wp_styles->queue);
     
      foreach($keys as $currentKey) {
        $keyToSplice = array_search($currentKey,$wp_styles->queue);
          if ($keyToSplice!==false && !is_null($keyToSplice)) {
            $elementToMove = array_splice($wp_styles->queue,$keyToSplice,1);
            $wp_styles->queue[] = $elementToMove[0];
          }
      }
    }
     
    add_action( 'wp_print_styles', 'swp_reorderstylesheets',10);
    Plugin Author Tom

    (@edge22)

    Yea, both are attached to wp_head as there isn’t a way to enqueue inline CSS without attaching it to an existing stylesheet.

    That’s strange, though. GB is added to wp_head with a priority of 10, so setting the Simple CSS priority to 9 should make it appear before.

    Any caching/minifying plugins that could be re-ordering things?

    Thread Starter pracko

    (@pracko)

    There’s no caching set up.

    After trying several ways to do it, I ended up going with another CSS plugin that outputs the CSS as an external stylesheet that I can put into the proper order using the above Action.

    Plugin Author Tom

    (@edge22)

    Glad you found a solution!

    I’ll look into implementing a filter in GB that allows you to control the position.

    Also, you can tell GB to use an external file instead of inline in Settings > GenerateBlocks.

    Thread Starter pracko

    (@pracko)

    Thanks Tom! Yeah, I am outputting the GB CSS as an external file so that I can control its order. But for whatever reason, I just can’t seem to get GB CSS to come dead last after the inline Simple CSS.

    Plugin Author Tom

    (@edge22)

    Have you tried lowering the priority in the simple css add_action I provided above? It can go all the way down to 0.

    Thread Starter pracko

    (@pracko)

    I did, but any lower than 8 put the Simple CSS before the theme’s (Neve) CSS. That’s why I switched to another custom CSS plugin — one that outputs an external file that I could then reorder basked on the key.

    Plugin Author Tom

    (@edge22)

    Makes sense. Adding an option to Simple CSS to build an external file is something I’d like to do eventually ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Load GB CSS Last’ is closed to new replies.