Created
October 16, 2016 20:55
-
-
Save stephanieleary/ae00bea06ff1513d48ed1fd9cbaca3eb to your computer and use it in GitHub Desktop.
Genesis titles for tag1+tag2 or tag1,tag2 combined term archives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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