I looked into this and it isn't currently possible to provide such a workaround for custom archives, because GeneratePress doesn't itself output content with blocks on archive pages, and so it isn't internally geared up for adding its block styles to archive pages, and hence there is no way to simply intervene and ensure that the styles are enqueued.
Adding such support is likely to require collaboration with the plugin developer, so I've added details to an internal ticket and am escalating this thread to it so that if we do get some news in the future I can update you.
I had a discussion with Tom Usborne, the developer of GeneratePress, and he said that - "he hasn't heard much from Toolset at all when it comes to integration".
Besides, he also said that - "Toolset would need to apply this kind of fix to make GB compatible with their plugin: hidden link
It's quite an easy fix - not sure why it hasn't been implemented."
I went back and took another look at the possibility of getting it to work on custom archive pages, and I have it working on my local test site.
Let me share the code with you, and if you confirm it works I'll update the internal ticket and the erratum so other users can benefit until the developers include a formal solution.
add_filter('generateblocks_do_content', function ($content) {
// Array of post types slugs which use Content Templates or custom WPAs
$post_types = array( 'thing' );
if ( is_singular( $post_types ) )
{
global $post;
// is the post being displayed with a Content Template?
$template_id = apply_filters( 'wpv_content_template_for_post', 0, $post );
if (isset($template_id) && !empty($template_id))
{
if (has_blocks($template_id))
{
$template = get_post($template_id);
// Append the template "content" to the post content, for scanning by GP
$content .= $template->post_content;
}
}
} elseif ( is_post_type_archive( $post_types ) )
{
// is there a custom WPA for this post type?
$post_type = get_query_var( 'post_type' );
$wpa_id = wpv_has_wordpress_archive( 'post', $post_type );
if (isset($wpa_id) && !empty($wpa_id))
{
$wpa_helper = get_posts
( array
(
'post_type' => 'wpa-helper',
'post_parent' => $wpa_id,
'post_status' => 'publish'
)
);
if (isset($wpa_helper) && !empty($wpa_helper))
{
if (has_blocks($wpa_helper[0]))
{
$content .= $wpa_helper[0]->post_content;
}
}
}
}
return $content;
});
You only need to specify the slugs of the custom post types you want this to work with (for content templates and custom post archives) at the top.
I had a small issue with adding CPT slugs but figured it out quickly. Just in case, beginners or newcomers shouldn't face the same problem, I am putting it down here:
add_filter('generateblocks_do_content', function ($content) {
// Array of post types slugs which use Content Templates or custom WPAs
$post_types = array( 'slug-1', 'slug-2', 'slug-3' );
if ( is_singular( $post_types ) )
{
global $post;
// is the post being displayed with a Content Template?
$template_id = apply_filters( 'wpv_content_template_for_post', 0, $post );
if (isset($template_id) && !empty($template_id))
{
if (has_blocks($template_id))
{
$template = get_post($template_id);
// Append the template "content" to the post content, for scanning by GP
$content .= $template->post_content;
}
}
} elseif ( is_post_type_archive( $post_types ) )
{
// is there a custom WPA for this post type?
$post_type = get_query_var( 'post_type' );
$wpa_id = wpv_has_wordpress_archive( 'post', $post_type );
if (isset($wpa_id) && !empty($wpa_id))
{
$wpa_helper = get_posts
( array
(
'post_type' => 'wpa-helper',
'post_parent' => $wpa_id,
'post_status' => 'publish'
)
);
if (isset($wpa_helper) && !empty($wpa_helper))
{
if (has_blocks($wpa_helper[0]))
{
$content .= $wpa_helper[0]->post_content;
}
}
}
}
return $content;
});