• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Programmatically Assign Templates

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Programmatically Assign Templates

This topic is: resolved

Tagged: custom, post, programmatically, taxonomy, template, term, type

  • This topic has 3 replies, 2 voices, and was last updated 10 years, 1 month ago by Brad Dalton.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • April 1, 2015 at 1:43 pm #146388
    Porter
    Participant

    Is there a way to programmatically assign which template a custom taxonomy term should use? I have the following Custom Post Types, and Taxonomies, using the Genesis framework:

    Dining (custom post type)

    dining_types (custom taxonomy)
    -restaurants (term)
    -cafes (term)
    -delis (term)
    -street vendors (term)

    Lodging (custom post type)

    lodging_types (custom taxonomy)
    -hotels (term)
    -inns (term)
    -bed and breakfasts (term)
    -resorts (term)

    Rather than create 8 templates, I could dynamically use the term name to serve related content (I have this working with a Page setup right now, but I'm switching to custom post types and taxonomies). Is there any way to simply tell all 8 of those terms to use "special-template.php" or whatever naming convention would be needed? The only detail is that they all need to use the same file, or at least 1 file per custom Taxonomy. I just need each term to be site.com/custom-taxonomy/term, as HUB page (custom template), and I'm not sure the best way to go about it.

    This could would preferably go in my site-specific plugin, or functions.php.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 1, 2015 at 5:56 pm #146404
    Brad Dalton
    Participant

    The template_include function does that.


    Tutorials for StudioPress Themes.

    April 1, 2015 at 6:19 pm #146409
    Porter
    Participant

    That should do it, thanks once again, Brad.

    So in theory, I should be able to write something like this:

    add_filter( 'template_include', 'my_callback' );
     
    function my_callback( $original_template ) {
      if ( is_tax($myCustomTaxonomy) ) {
        return SOME_PATH . '/some-custom-file.php';
      } else {
        return $original_template;
      }
    }

    I just looked up and discovered the is_tax function, and that appears to be the other piece of the puzzle. I really should spend 15-30 minutes browsing the codex once a week - things like this wouldn't slip passed me.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    April 1, 2015 at 6:23 pm #146410
    Brad Dalton
    Participant

    All you should need to do is work out the correct conditional tag.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble