I’m making a plugin which includes a custom post type with custom taxonomies.

I have a custom template – taxonomy-coupon-category.php – but these template files are specific to a single theme.

What is the best practice to make my plugin include a custom taxonomy/archive template which works for ALL themes?

My custom code only needs to alter the loop and the internals of the loop. The problem is really that the template includes other theme specific html e.g. sidebar location, other stuff.

<?php get_header(); ?>
<!-- my unique content -->
<?php get_footer(); ?>

It’d be great if this code above would work on all themes but it doesn’t (e.g. sidebar might be missing, or with roots theme header/footer appears twice) – how do other plugins manage to create custom archives and custom taxonomy templates which work on all themes?

I just need my taxonomy-coupon-category.php file to replace the loop generated content and leave the theme to handle the surrounding html.

1 Answer
1

Creating pages is the job of a theme, plugins should not attempt to do that. What you can do is to provide a shortcode which will add the relevant html when used and let the user add it as part of his content however he wants to use it.

That said, if you really must have something automatic you can use the page.php template of the active theme and supply your own content by using the the_content and the_title filters. This should work for most themes with a simple page design.

Leave a Reply

Your email address will not be published. Required fields are marked *