• 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.php

    Class: ContentBlocksTemplates

    For single templates, the constructor only:

    1. Sets the global $blocksy_template_output = true (line 25)
    2. Adjusts page_structure via the blocksy:global:page_structure filter (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 — in template-parts/single.php:24, replaces the entire single page
    • blocksy:single:content:custom-output — in inc/components/single/content-helpers.php:253, replaces only the the_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-output and returns blocksy_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-output inside ContentBlocksTemplates::__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.php or 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);
    });
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.