• Hi folks,
    I’d like to load a custom header on single.php based on whether the post contains a custom taxonomy term or not.
    I’ve tried this, but it’s not working:

    $terms = get_the_terms( $post->ID, 'custom-taxonomy' );
    if ( has_term( 'custom-taxonomy-term' )) {
    get_header('header-custom');
    } else {
    get_header();
    }

    I’ve been googling like crazy and trying so many variations but I’m stuck.
    Any help much appreciated? Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • have you tried to specify the custom tax name in your call to has_term?

    has_term( ‘custom-taxonomy-term’ , ‘custom-taxonomy’)

    be careful though, you might want to include an is_single() in that conditional, because you don’t want the custom header if it’s an archive and the special post is at the top!

    this is untested, and is more a less a guess – so hit me up w/ any questions!

    Thread Starter ViscoDesign

    (@viscodesign)

    Oh my god, yes! Awesome, that worked. Thank you!

    I’ve created a new single-custom.php to handle the Custom Post Types so it’s all good. It shouldn’t interfere with any other templates/posts.

    Thanks again!

    Thread Starter ViscoDesign

    (@viscodesign)

    This is the final code that works…

    if ( has_term( 'custom-taxonomy-term', 'custom-taxonomy' )) {
    get_header('header-custom');
    } else {
    get_header();
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Call custom header based on custom taxonomy term?’ is closed to new replies.