• I have created a block theme using Gutenberg’s full-site editing to customize the templates. However, there is an issue now, I want to use a custom template file to replace the default WordPress template-canvas.php file. Is there any way to do this?
    Becaruse of I want to add some additional containers wrapping all the blocks based on the <div class="wp-site-blocks"> container.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can follow these step.

    • Develop your custom template file, for example, custom-template.php, with the desired structure.
    • Ensure to include the necessary WordPress functions for header, footer, and content.
    • In your theme folder, locate the template-canvas.php file.
    • Replace its content or rename it to keep a backup, and then paste the content of your custom template file.
    • Edit your custom template to add the additional containers you need, wrapping the blocks within <div class="wp-site-blocks"> or as per your requirements.
    • Save the changes and update your theme files.
    Thread Starter weweloo

    (@weweloo)

    template-canvas.php is a core file in WordPress located in the wp-includes folder. I don’t want to modify any files outside of the theme, as it would impact future WordPress updates. I prefer making all changes within the theme files.

    You can use a combination of theme files and filters to accomplish your purpose. Here’s an easier method:

    Create a Custom Template in Your Theme:

    • In your theme folder, create a new file, e.g., custom-template.php.
    • Customize this file with your desired structure, including additional containers around blocks.

    Use template_include Filter:

    • Open your theme’s functions.php file.
    • Use the template_include filter to conditionally load your custom template file instead of the default template-canvas.php. Here’s an example:

    function custom_template_include($template) { // Check if it's the template-canvas.php being loaded if (is_page_template('template-canvas.php')) { // Use your custom template file $custom_template = locate_template('custom-template.php'); if ($custom_template != '') { return $custom_template; } } return $template; } add_filter('template_include', 'custom_template_include');

    This filter checks if the current template being loaded is template-canvas.php and replaces it with your custom template if it exists in the theme.

    • Save your changes and update your theme files.


      Hope this will help you….
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Issue with Block Theme Templates’ is closed to new replies.