Skip to content

Instantly share code, notes, and snippets.

@pablocattaneo
Last active September 16, 2017 00:17
Show Gist options
  • Save pablocattaneo/594f5d4cccb9513de34e to your computer and use it in GitHub Desktop.
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…
<?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