-
hogmalms
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.
-
hogmalms
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 ? -
hogmalms
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 thegenerateblocks_maybe_add_block_css
function can be used for this. -
hogmalms
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.
- You must be logged in to reply to this topic.