Use STYLESHEETPATH
instead of TEMPLATEPATH
. You’ll find the definitions in wp-includes/default-constants.php
file. Please have look. So your code block will be like below-
//Gets post cat slug and looks for single-[cat slug].php and applies it
add_filter('single_template', create_function(
'$the_template',
'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(STYLESHEETPATH . "/single-{$cat->slug}.php") )
return STYLESHEETPATH . "/single-{$cat->slug}.php";
}
return $the_template;'
)
);
Hope that helps you.
Related Posts:
- WordPress Multisite – global categories
- Get posts from sites in Multisite?
- How do I get the category URL from get_the_category?
- Multisite – Protect categories from deletion?
- Category page doesn’t use category.php, instead it redirects to homepage
- 5 blogs on one WordPress site
- Multisite blog converting categories to subdomains
- Adding categories to all blogs at once
- Create single.php for specific category by category id
- WordPress MU 2.9.2 to 3.0.5 changes to category.php
- How to make category RSS feeds show full content
- How to get category id in single.php wordpress?
- Multi-site or categories?
- Multisite – create a category in specific site
- WordPress Multisite – global categories
- Default category link for a custom category is a broken link
- in_category() works in single.php but not in page.php?
- Archives for each category on WP Multisite
- previous/next_post_link in the same sub-category?
- Send to different single pages by category when multiple categories exist
- How do I share categories across selected sites in a Multisite setup
- get_categories() returns “Uncategorised”
- How to make the link to the category for a post go to corresponding page number in archive?
- wordpress multisite… collect all posts on main blog – exclude category?
- Can Categories be used to hack a Multisite-like setup w/ a single MySql db?
- Single.php Category Post Count
- Problems with my conditionals in single.php by category
- Get next post in same category not working WP 4.7.4
- Simple way to style posts of a single category differently in the loop and in single
- How to Sync Menu, Widgets and other masters from Main Website to its Sub Site
- How to get nav to show current_page_parent class when on regular post (not blog), differentiated by category
- How can I check which archive has referred the single? [closed]
- Displaying links to all posts of the same category on the post page
- Categories show 404 error on multisite installation
- Global navigation in multisite: problem with categories
- Duplicate new categories across multisite network
- Ignore the Ad on Specific Categories
- custom wp_list_categories in single.php
- get_the_category return empty inside loop
- loop in single.php of the same category
- Display Some text in some specific category not all category
- When category name and title are the same … WP will select archive.php instead of single.php
- global categories – Share specific categories in wordpress multisite
- Limit Category/Tag Dropdown To blog_id in Multisite Install With Global Categories/Tags
- Code to display category-specific single.php is overriding normal single.php, too
- A search box for all sites – Multisite
- Display Referring Category on single post?
- How to create default categories in new installs?
- Multiple parent categories
- Modify / Rewrite single template url structure
- How to populate a WordPress install with a lot of categories, quickly?
- How to structure Multisite sites into categories?
- How do I get a single page navigation depending on the previous page?
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Is There a Difference Between Taxonomies and Categories?
- List all subcategories from category
- How To Find Out WordPress Category Table in MYSQL?
- Add custom field to Category
- Get Category ID inside Category template
- Only one category per post
- Get the children of the parent category
- WP REST API: filter by category 1 AND category 2
- How To Get Parent Category Slug of Current Post
- Display All Products by Category with WooCommerce
- What is the difference between a “tag” and a “category”?
- Is there an easy way to make a meta box have the tabs like the Categories meta box has?
- How to check if I’m on the last page of posts?
- Display posts from the same category using next/previous post link
- How would I get a taxonomy/category list inside a Gutenberg block?
- Can I set a default featured image for a category?
- Check if a post is in any child category of a parent category
- How to export and import taxonomies (category, tag and/or custom taxonomy) and their terms
- Force category choice before creating new post?
- Gutenberg editor add a custom category as wrapper for custom blocks
- WooCommerce: List All Categories
- How to get category and archive title?
- Get category ID from category slug (not working)
- How do I remove “Uncategorized” from posts with more than 1 category?
- Get rid of WordPress category, tag and author archives?
- Individual rss feed entry length for categories?
- How can I create a category landing page followed by pages of posts?
- Remove parent category from permalink? Basically only have the child category?
- Custom permalink structure leads to be 404 on pagination
- Retrieve Product category ‘NAME’ by product category ID – WooCommerce?
- Posts URL structure like site.com/category/the-post-title
- Can’t custom taxonomies have same terms (slugs) as categories?
- How to get permalinks with category base working with sub-categories
- How to remove the term “category” from category pagination?
- Using wp_category_checklist in a widget
- WP 3.9 TinyMCE no longer loads on category description editor
- On the category page, get the category object
- Get only the top level categories using get_categories() without foreach loop
- Get all categories and posts in those categories
- How to add featured image for category (without a plugin)?
- How to create a custom sort for WordPress categories
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Category archive by year with permalink support /category/YYYY
- Best Way to Redirect Category to Page and Hide Category
- get_terms vs. get_categories: does it matter?
- What is a good robots.txt?