Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Genesis titles for tag1+tag2 or tag1,tag2 combined term archives
<?php
// Have to unhook the original function early
add_action( 'init', 'scl_fix_taxonomy_archive_titles' );
function scl_fix_taxonomy_archive_titles() {
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
add_action( 'genesis_before_loop', 'scl_do_taxonomy_title_description', 14 );
}
function scl_do_taxonomy_title_description() {
if ( ! is_category() && ! is_tag() && ! is_tax() )
return;
if ( is_search() )
return;
$taxonomy = get_query_var( 'taxonomy' );
$topics = get_query_var( $taxonomy );
if ( is_array( $topics ) )
$topics = implode( ',', $topics );
$hascomma = strpos( $topics, ',' );
$hasplus = strpos( $topics, '+' );
if ( $hascomma !== false OR $hasplus !== false ) {
if ( $hascomma ) {
$sep = ',';
$glue = ' or ';
}
else {
$sep = '+';
$glue = ' and ';
}
$newtitles = array();
$terms = explode( $sep, $topics );
foreach ( $terms as $single ) {
$termobj = get_term_by( 'slug', $single, $taxonomy );
$newtitles[] = $termobj->name;
}
$headline = sprintf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), implode( $glue, $newtitles ) );
printf( '<div %s>%s</div>', genesis_attr( 'taxonomy-archive-description' ), $headline );
return;
}
else
add_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.