I have a plugin that I am developing that is using custom post types and taxonomies. My question is this. How can I load the content/theme data from my plugin on to the page when the go to the custom url of the taxonomy?
EDIT
I am trying to use the plugin’s template files and not the themes for my custom taxomony.
First of all – plugins are for generating content, themes are for displaying it. So really, a plugin shouldn’t do this. But there are grey areas – for example in an ‘events’ related plugin, it would be desirable to display dates, venue etc – things that a WordPress theme wouldn’t normally display.
I would suggest
To alter the template being used you can use the
template_include
filter. This is an example for taxonomy templates, but a similar process is possible for custom post types.Note it assumes that the plugin templates are in a template sub-folder relative to current director.
Logic
This simply checks that the ‘event-venue’ taxonomy is being viewed. If not it will use the original template.
The
wpse50201_is_template
function will check if the template WordPress has picked from the theme/child-theme is calledtaxonomy-event-venue.php
ortaxonomy-event-venue-{term-slug}.php
. If it is – the original template will be used.This allows users of your plugin to copy them into their theme and edit them, and the plugin will prioritize the theme/child-theme templates. Only if it can’t find them does it fall back to the plug-in templates.
I’ve used this method in a plugin – you can see a working example of the above here.
This is how I’m calling a taxonomy template from a subdirectory within my theme folder. Keep in mind that
taxonomy.php
will need to stay in your root theme directory.For example, my taxonomy is called ‘news-category’. The template is located at
wp-content/themes/mytheme/templates-taxonomy/taxonomy-news-category.php