Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Last active March 29, 2018 20:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/a0ad40ead9e724f87b0e8ee955dd3c60 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/a0ad40ead9e724f87b0e8ee955dd3c60 to your computer and use it in GitHub Desktop.
Use Taxonomy Name for Default Taxonomy Archive Title in Genesis
<?php
/**
* Default Titles for Term Archives
*
* @author Bill Erickson
* @see http://www.billerickson.net/default-category-and-tag-titles
*
* @param string $headline
* @param object $term
* @return string $headline
*/
function ea_default_term_title( $value, $term_id, $meta_key, $single ) {
if( ( is_category() || is_tag() || is_tax() ) && 'headline' == $meta_key && ! is_admin() ) {
// Grab the current value, be sure to remove and re-add the hook to avoid infinite loops
remove_action( 'get_term_metadata', 'ea_default_term_title', 10 );
$value = get_term_meta( $term_id, 'headline', true );
add_action( 'get_term_metadata', 'ea_default_term_title', 10, 4 );
// Use term name if empty
if( empty( $value ) ) {
$term = get_term_by( 'term_taxonomy_id', $term_id );
if( $term ) {
$value = $term->name;
}
}
}
return $value;
}
add_filter( 'get_term_metadata', 'ea_default_term_title', 10, 4 );
@Crunchify
Copy link

Thanks Joshua. How could I add category description after title field? I tried modifying above code with multiple different approaches without luck. Any help you could share?

@joshuadavidnelson
Copy link
Author

joshuadavidnelson commented Jun 10, 2016

I've updated the code per Bill Erickson's new method, which is cleaner than my first version, see his post.

For outputting the description, you'll want to hook a function where you can output echo term_description( $term_id, $taxonomy ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment