WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


I am trying to use the plugin's template files and not the themes for my custom taxomony.

share|improve this question
Could you be more specific, are you trying to get WordPress to use the plug-in's template files rather than their themes? – Stephen Harris Apr 25 '12 at 15:51
@StephenHarris Yes that is exactly what I am trying to do. – brenjt Apr 25 '12 at 15:54
up vote 5 down vote accepted

First of all - plug-ins are for generating content, themes are for displaying it. So really, a plug-in shouldn't do this. But there are grey areas - for example in an 'events' related plug-in, it would be desirable to display dates, venue etc - things that a WordPress theme wouldn't normally display.

I would suggest

  • making the plug-in templates over-rideable with templates of the same name in the theme/child theme.
  • Being able to 'turn off' plug-in forcing of the template.

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.

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

    //Add option for plug-in to turn this off? If so just return $template

    //Check if the taxonomy is being viewed 
    //Suggested: check also if the current template is 'suitable'

    if( is_tax('event-venue') && !wpse50201_is_template($template)
        $template = plugin_dir_url(__FILE__ ).'templates/taxonomy-event-venue.php';

    return $template;

Note it assumes that the plug-in templates are in a template sub-folder relative to current director.


This simply checks that the 'event-venue' taxonomy is being viewed. If not it will use the original template.

The wpse50201_template function will check if the template WordPress has picked from the theme/child-theme is called taxonomy-event-venue.php or taxonomy-event-venue-{term-slug}.php. If it is - the original template will be used.

This allows users of your plug to copy them into their theme and edit them, and the plug-in will prioritise the theme/child-theme templates. Only if it can't find them does it fall back to the plug-in templates.

function wpse50201_is_template( $template_path ){

    //Get template name
    $template = basename($template_path);

    //Check if template is taxonomy-event-venue.php
    //Check if template is taxonomy-event-venue-{term-slug}.php
    if( 1 == preg_match('/^taxonomy-event-venue((-(\S*))?).php/',$template) )
         return true;

    return false;

I've used this method in a plug-in - you can see a working example of the above here.

share|improve this answer
thanks for the answer. Trying this out it overwrites the entire theme including the head and foot. How can I get it to use the theme but the body content is replaced with mine? – brenjt Apr 25 '12 at 16:45
you just call get_header() and get_footer() in the custom template. – Stephen Harris Apr 25 '12 at 16:48
Perfect. that worked just as I had hoped. Thank you!! I was wondering if this was even possible – brenjt Apr 25 '12 at 17:53

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.

function call_taxonomy_template_from_directory(){
    global $post;
    $taxonomy_slug = get_query_var('taxonomy');
    load_template(get_template_directory() . "/templates-taxonomy/taxonomy-$taxonomy_slug.php");
add_filter('taxonomy_template', 'call_taxonomy_template_from_directory');

For example, my taxonomy is called 'news-category'. The template is located at wp-content/themes/mytheme/templates-taxonomy/taxonomy-news-category.php

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.