Last active
June 26, 2022 15:26
-
-
Save jaredatch/1256954 to your computer and use it in GitHub Desktop.
Using the template_include filter in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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