• Resolved challet

    (@challet)


    Hello,

    Using a category_template filter to route the template picking from a custom condition :

    <?php
    add_filter('category_template', function ( $template ) {
      $category = get_queried_object();
      // custom condition 
      if( $category->parent == 1 ) {
        $template = locate_template('templates/category-1.html');
      }
    
      return $template;
    });

    When requesting the category 1 page directly, everything goes right so it’s not about the template format itself.

    But, when requesting one of its child and entering the custom condition, it’s like the template is not seen as a template and the html answer shows the raw content of the file :

    <!-- wp:template-part {"slug":"header","tagName":"header"} /-->
    […]
    <!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

    What am I missing ?

    • This topic was modified 6 months, 4 weeks ago by challet.
Viewing 1 replies (of 1 total)
  • Thread Starter challet

    (@challet)

    Self-answer : Block templates need an other function locate_block_template to create a usable return :

    <?php
    add_filter('category_template', function ( $template ) {
      $category = get_queried_object();
      // custom condition
      if( $category->parent == 1 ) {
        $template = locate_block_template('templates/category-1.html', 'category-1', []);
      }
      return $template;
    });
Viewing 1 replies (of 1 total)
  • The topic ‘Custom template not parsed and answsers with the raw code’ is closed to new replies.