Languages: English • 한국어 • (Add your language)
This hook can be used to filter the default WordPress Template Hierarchy and load a custom category template.
This example loads a custom category template for categories 62,65 and 59.
add_filter( 'category_template', 'filter_category_template', 99 ); function filter_category_template( $template ) { if ( is_category(array( 64,65,59 ) ) ) { $new_template = locate_template( array( 'category-template.php' ) ); if ( '' != $new_template ) { return $new_template; } } return $template; }
Here's another way to write the code
add_filter( 'category_template', 'custom_category_template' ); function custom_category_template( $template ) { if ( is_category(array( 64,65,59 ) ) ) { $template = locate_template( 'custom.php' ); } return $template; }
This filter is applied in wp-includes/template-loader.php