The Bobster
The Bobster

Reputation: 573

WordPress: Adding a custom post type taxonomy template in plugin

I've created a custom post type named "accommodation" and taxonomy for it named "categories" using the file "taxonomy-accommodation-categories.php" - this is working fine in my WordPress theme.

But I want to add this in a separate plugin instead, does anyone know how I can do this?

Appreciate any help, thanks.

Upvotes: 1

Views: 924

Answers (3)

Mostafa Norzade
Mostafa Norzade

Reputation: 1766

This is must work :


add_filter('template_include', 'taxonomy_template');
function taxonomy_template( $template ){

if( is_tax('accommodation-categories')){
    $template = BASE_DIR .'/templates/taxonomy-accommodation-categories.php';
}  

return $template;

}

Upvotes: 0

Dahituc
Dahituc

Reputation: 3

The wordpress codex has instructions on how to do this, https://codex.wordpress.org/Plugin_API/Filter_Reference/single_template

The github link posted before also has the same thing but more explained

Upvotes: 0

vishalbasnet23
vishalbasnet23

Reputation: 313

I think this is what you are looking for. https://gist.github.com/vishalbasnet23/4cf739624ba3b75e75d8

Upvotes: 1

Related Questions