• Love the plugin, but one annoyance is that references to specific navigation post IDs are included in headers or anywhere else a header block appears. If you then use the theme on a different site, users get an error saying the menu can’t be found because it references a post ID that doesn’t exist or doesn’t correspond to a navigation document.

    I came up with my own workaround, which I’d suggest could be incorporated in future versions of the plugin (and improved upon, no doubt). If there are cases where including the “ref”: ID is desirable behavior, than maybe having something like this turned on could be an optional preference.

    <?php
    
    /*
    
    Plugin Name: Create Block Theme Hack
    
    */
    
    //remove ref from templates / template parts
    
    add_filter('get_block_templates','create_block_theme_clear_references');
    
    function create_block_theme_clear_references($templates) {
    
        if(strpos($_SERVER['REQUEST_URI'],'create-block-theme')) {
    
            //if this was called from the Create Block Theme admin page or API as part of an export
    
            foreach($templates as $template) {
    
                $template->content = preg_replace('/\{"ref":[0-9]+\}/','',$template->content);
    
                $template->content = preg_replace('/"ref":[0-9]+,/','',$template->content);
    
            }
    
        }
    
        return $templates;
    
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Remove “ref” reference to an ID from navigation blocks in exported themes’ is closed to new replies.