Skip to content
WJunction - Webmaster Forum

How can i conditionally load taxonomy-{taxonomy}.php template files through functions.php

Status
Not open for further replies.


SCAMMER WARNING - DO NOT PURCHASE OR DEAL WITH THIS USER.
SEE THIS THREAD:

I would like to conditionally load the taxonomies of actors and directors only if a option of my theme is active.
At the moment in the root theme folder i have these 2 files

Code:
taxonomy-actors.php
taxonomy-directors-php

I would like them to be used only if the function is active.

For example:

Code:
        if ($theme_comments == 1)
        {
         //load taxonomy
        } else {
        //don't load taxonomy
        }
 
Last edited by a moderator:

2 comments

Post the question in stackoverflow also, it may help you
Already done
Post automatically merged:

Find the solution :)

Code:
if ($moviewp_comments == 1) { 

add_filter( 'template_include', 'wpse_template_include' );
function wpse_template_include( $template ) {
    // Handle taxonomy templates.
    $taxonomy = get_query_var( 'taxonomy' );
    if ( is_tax() && $taxonomy ) {
        $file = get_theme_file_path() . '/templates/taxonomy-' . $taxonomy . '.php';
        if ( file_exists( $file ) ) {
            $template = $file;
        }           
    }

    return $template;
}
} else { 

}
 
Last edited:
Status
Not open for further replies.

About the author

fr0zen
Active Member · Joined
252
Messages
75
Reactions
28
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom