Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Last active June 26, 2022 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jaredatch/1256954 to your computer and use it in GitHub Desktop.
Save jaredatch/1256954 to your computer and use it in GitHub Desktop.
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