Last active
September 16, 2017 00:17
-
-
Save pablocattaneo/594f5d4cccb9513de34e to your computer and use it in GitHub Desktop.
If you want to create a custom template for WordPress Posts, which belong to a specific category for example you can’t just create single-catname.php. The solution to this is also not complicated at all. You need to create a function and preferably save it in your theme’s functions.php file.
Here’s how to create a custom post template for a spec…
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 | |
function get_custom_cat_template($single_template) { | |
global $post; | |
if ( in_category( 'category-name' )) { | |
$single_template = dirname( __FILE__ ) . '/single-template.php'; | |
} | |
return $single_template; | |
} | |
add_filter( "single_template", "get_custom_cat_template" ) ; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment