Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using the template_include filter in WordPress
<?php
add_filter( 'template_include', 'ja_template_check' );
function ja_template_check( $template ) {
if ( is_category() ){
// Get category information
$cat = get_query_var( 'cat' );
$category_info = get_category( $cat );
// News sub-categories, where 7 is the ID for News
if ( $category_info->parent == 7 ){
return get_stylesheet_directory() . '/subcategory-news.php';
}
}
return $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment