Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

CSS is breaking in loop when filtering with Ajax

  • Hello,

    I have a query loop, where I show some posts from a custom post type. I have some fields attached to this post type, and I managed to create an AJAX filter depending on the field.

    The filter is working, and correct posts is showing when I filter. But I have one issue.
    All the css for the loop is gone when I filter (even the standard built in css for generateblocks). Do you have any idea why this is happening?

    Best regards,
    Andreas

  • Hi there,

    its suspect its the dynamic CSS generation that GenerateBlocks uses, which is compiled when the page is rendered which won’t happen on your Ajax loading.
    I need to check with Tom as there were discussions for a filter to change that behaviour, but I am not sure if it made the last update or not.

    The alternative would be to use Global Styles to style the blocks. It means the CSS gets loaded regardless and only the once for those blocks.

  • Hello David,

    Thank you for the quick response.

    Are you refering to this filter?
    https://docs.generateblocks.com/article/adding-content-sources-for-dynamic-css-generation/

  • That particular filter tells GB to check other post types for the blocks, which works when the blocks are rendered on page load.

    The issue here I assume is related to the Ajax Loading of your blocks.
    Does the CSS load correctly without the Ajax loading ?

  • Yes you’re right. I tried generateblocks_do_content filter and did not manage to get it working.

    The issue here I assume is related to the Ajax Loading of your blocks.

    Yes, this is correct.

    Does the CSS load correctly without the Ajax loading ?

    Yes.

  • Yeah, so I would recommend using Global Styles to style the blocks for now. As those will load regardless.
    But ill pass this topic onto Tom to see if the generateblocks_maybe_add_block_css function can be used for this.

  • Alright, thank you David for the support!

    Looking forward to a solution.

  • You could try this PHP snippet:

    
    add_filter( 'generateblocks_do_inline_styles', function( $do ) {
        $do = true;
    
        return $do;
    } );
    

    It forces GB to inline the block styles.
    May want to add a conditional template tag to the function eg.

    
    add_filter( 'generateblocks_do_inline_styles', function( $do ) {
        if( is_home() ) {
            $do = true;
        }
        return $do;
    } );
    

    Which would limit the function to the blog page.

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