Quantcast
Channel: Suzanne Ahjira» Tutorials
Viewing all articles
Browse latest Browse all 29

Force Custom Archive Titles for All Archives

$
0
0

I found and customized this solution a long time ago, and I forget why I had to do it this way. There may be a more efficient method at this point, and I’ll investigate that, but for now, if you’d like to force archive pages to show the archive title – even a custom title like I’ve got – then you can use this code.

Note: Archives get a title if you enable it in each archive’s settings but I don’t like having to do that for each archive I create. That’s why I like this solution. It does it for me regardless of whether I’ve set it in settings or not.

add_action('genesis_before_loop', 'child_do_taxonomy_title_description', 15); 
function child_do_taxonomy_title_description() { 
    global $wp_query; 
     
    if ( !is_category() && !is_tag() && !is_tax() ) 
        return; 
         
    if ( get_query_var('paged') >= 2 ) 
        return; 
         
    $term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : $wp_query->get_queried_object(); 
     
    if ( !$term || !isset( $term->meta ) ) 
        return; 

    global $_genesis_formatting_allowedtags; 
         
    $title = sprintf( '<h1>%s</h1>', esc_html( $term->name ) ); 
    $description = wpautop( wp_kses( $term->description, $_genesis_formatting_allowedtags ) ); 

    if ( $title || $description ) { 
        printf( '<div class="taxonomy-description"><span>Archive for</span>%s</div>', $title . $description ); 
    }

}

Notice that I’ve included a <span>Archive for</span> within the output. This allows me to display that text above the title itself (as you can see on any of my archive pages). Use the CSS below to achieve the same effect.

.taxonomy-description span {
   display: block;
   font-size: 14px;
   text-transform: uppercase;
}

Viewing all articles
Browse latest Browse all 29

Trending Articles