Issues with styling for generateblocks being removed for custom post types, plugins

I had an issue where Generatepress styles were lost on the front end for a variety of plugins i was using (toolset, reusable blocks etc)

There was a fix in some circumstances but it was not for the whole post type and had to be done one by one… so I figured it out (I am not a PHP dev so use with caution, or if a dev could check it out that would be handy).

Add this to the functions.php of a child template, or in your fav code plugin.

add_filter( 'generateblocks_do_content', 'generateblock_template_support_testing', 10, 2);

function generateblock_template_support_testing($content) {

$args = array(
‘numberposts’ => -1, // get all posts in custom post type
// ‘include’ => array(), //specify specific posts to include for performance
// ‘exclude’ => array(), //specify specific posts to exclude for performance
‘post_type’ => ‘view-template’, //change this to the custom post type slug you want to reference
$my_posts = get_posts( $args );

if( ! empty( $my_posts ) ){

foreach ( $my_posts as $p ){
if ( has_blocks( $p ) ) {   //test to see if blocks present, if so continue
$content .= $p->post_content; //gets the content so the GeneratePress filter can scan and apply styles

return $content;


Thats should do it…

Just be aware that the idea I am guessing for the Tom and the team is not to load resources where they are not needed, so whilst this does resolve the issues where there is un styled content … just remember it will come at an overall performance price depending on your site…

you can however in the code above just include the post ids for the ones using GenerateBlocks… so, test away.

1 Like

There is a page in the docs that explains why this happens and what to do to resolve it. Hope it helps!

Adding content sources for dynamic CSS generation - Documentation (