Bug Report: Content Block — Single template does not render
-
Environment
- Plugin: Blocksy Companion Pro
- Theme: Blocksy
Description
When creating a Content Block with Template Type = Single and setting a display condition (e.g.
Include {CPT} Single), the single page for that post type is not overridden by the Content Block. The original Gutenberg content is still displayed instead.The same scenario works perfectly for Template Type = Archive. Root Cause
File:
framework/premium/features/content-blocks/templates.phpClass:
ContentBlocksTemplatesFor single templates, the constructor only:
- Sets the global
$blocksy_template_output = true(line 25) - Adjusts
page_structurevia theblocksy:global:page_structurefilter (lines 133-163)
But it never hooks into the filter that actually replaces the page content. The Blocksy theme provides two filters for this:
blocksy:single:canvas:custom-output— intemplate-parts/single.php:24, replaces the entire single pageblocksy:single:content:custom-output— ininc/components/single/content-helpers.php:253, replaces only thethe_content()area
Neither is used by the plugin for single templates.
Compare with the archive handling, which works correctly (same file, lines 53-94): it hooks into
blocksy:posts-listing:canvas:custom-outputand returnsblocksy_companion_render_content_block($maybe_hook_id). Current code (single — incomplete):// templates.php, lines 11-27 (that's all there is for single) add_action('wp', function () { if (! is_singular() && ! is_single()) { return; } if ( function_exists('blocksy_companion_get_content_block_that_matches') && blocksy_companion_get_content_block_that_matches([ 'template_type' => 'single', 'template_subtype' => 'canvas' ]) ) { global $blocksy_template_output; $blocksy_template_output = true; } });Archive code (complete — works):
// templates.php, lines 53-94 add_filter( 'blocksy:posts-listing:canvas:custom-output', function ($output) { // ... nothing_found check ... $maybe_hook_id = null; if ( blocksy_companion_get_content_block_that_matches([ 'template_type' => 'archive', 'template_subtype' => 'canvas' ]) ) { $maybe_hook_id = blocksy_companion_get_content_block_that_matches([ 'template_type' => 'archive', 'template_subtype' => 'canvas' ]); } if (! $maybe_hook_id) { return $output; } global $blocksy_template_output; $blocksy_template_output = true; return blocksy_companion_render_content_block($maybe_hook_id); } );Suggested Fix
Add a hook into
blocksy:single:canvas:custom-outputinsideContentBlocksTemplates::__construct(), following the exact same pattern already used for archives:add_filter( 'blocksy:single:canvas:custom-output', function ($output) { $maybe_hook_id = null; if ( blocksy_companion_get_content_block_that_matches([ 'template_type' => 'single', 'template_subtype' => 'canvas' ]) ) { $maybe_hook_id = blocksy_companion_get_content_block_that_matches([ 'template_type' => 'single', 'template_subtype' => 'canvas' ]); } if (! $maybe_hook_id) { return $output; } global $blocksy_template_output; $blocksy_template_output = true; return blocksy_companion_render_content_block($maybe_hook_id); } );Workaround
Until the fix is shipped, the following snippet can be added via a child theme’s
functions.phpor a code snippets plugin:add_filter('blocksy:single:canvas:custom-output', function ($output) { if (! function_exists('blocksy_companion_get_content_block_that_matches')) { return $output; } $hook_id = blocksy_companion_get_content_block_that_matches([ 'template_type' => 'single', 'template_subtype' => 'canvas', ]); if (! $hook_id) { return $output; } global $blocksy_template_output; $blocksy_template_output = true; return blocksy_companion_render_content_block($hook_id); });
You must be logged in to reply to this topic.