Skip to content

Instantly share code, notes, and snippets.

@cpaul007
Last active October 13, 2021 11:04
Show Gist options
  • Save cpaul007/b1c0c007e068fc549091 to your computer and use it in GitHub Desktop.
Save cpaul007/b1c0c007e068fc549091 to your computer and use it in GitHub Desktop.
Display taxonomy title and desciption
<?php //* Don't include this PHP open tag
/**
* Filename: taxonomy_title_description.php
*
* @author Chinmoy Paul
* @link http://genesisdeveloper.me
* @copyright Copyright (c) 2015 Genesis Developer.
*/
//* Add this code in your functions.php file
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
add_action( 'genesis_before_loop', 'gd_do_taxonomy_title_description', 14 );
/**
* Add title and description to category / tag / taxonomy archive pages.
* If the page is not a category, tag or taxonomy term archive, or there's no term, or
* no term meta set, then nothing extra is displayed.
*
* If there have no intro text then default category description will appear
*
* @return null Return early if not the correct archive page, not page one, or no term meta is set.
*/
function gd_do_taxonomy_title_description() {
global $wp_query;
if ( ! is_category() && ! is_tag() && ! is_tax() )
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;
$headline = $intro_text = '';
if ( $term->meta['headline'] ) {
$headline = sprintf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), strip_tags( $term->meta['headline'] ) );
} else {
if ( genesis_a11y( 'headings' ) ) {
$headline = sprintf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), strip_tags( $term->name ) );
}
}
$desc = category_description( $term->term_id );
if ( ! empty ( $desc ) )
$intro_text = apply_filters( 'genesis_term_intro_text_output', $desc );
if( $term->meta['intro_text'] )
$intro_text = apply_filters( 'genesis_term_intro_text_output', $term->meta['intro_text'] );
if ( $headline || $intro_text )
printf( '<div %s>%s</div>', genesis_attr( 'taxonomy-archive-description' ), $headline . $intro_text );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment