Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active May 18, 2021 16:50
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 srikat/668ccfee42f992925e5d6720e6732a5c to your computer and use it in GitHub Desktop.
Save srikat/668ccfee42f992925e5d6720e6732a5c to your computer and use it in GitHub Desktop.
Display Portfolio CPT's linked taxonomy terms (categories and tags) in Genesis entry meta. https://sridharkatakam.com/displaying-cpt-taxonomy-terms-genesis-entry-footer/
add_shortcode( 'portfolio_terms', 'custom_portfolio_terms_shortcode' );
/**
* Produces the linked post taxonomy terms list.
*
* Supported shortcode attributes are:
* after (output after link, default is empty string),
* before (output before link, default is 'Tagged With: '),
* sep (separator string between tags, default is ', '),
* taxonomy (name of the taxonomy, default is 'category').
*
* Output passes through `genesis_post_terms_shortcode` filter before returning.
*
* @since 1.6.0
*
* @param array|string $atts Shortcode attributes. Empty string if no attributes.
* @return string Output for `post_terms` shortcode, or empty string on failure to retrieve terms.
*/
function custom_portfolio_terms_shortcode( $atts ) {
$defaults = array(
'after' => '',
'before' => __( 'Filed Under: ', 'genesis' ),
'sep' => ', ',
'taxonomy' => 'category',
);
/**
* Post terms shortcode defaults.
*
* Allows the default args in the post terms shortcode function to be filtered.
*
* @since 2.0.0
*
* @param array $defaults The default args array.
*/
$defaults = apply_filters( 'genesis_post_terms_shortcode_defaults', $defaults );
$atts = shortcode_atts( $defaults, $atts, 'post_terms' );
$terms = get_the_term_list( get_the_ID(), $atts['taxonomy'], $atts['before'], trim( $atts['sep'] ) . ' ', $atts['after'] );
if ( is_wp_error( $terms ) )
return '';
if ( empty( $terms ) )
return '';
if ( genesis_html5() )
switch ( $atts['taxonomy'] ) {
case 'portfolio_tag':
$output = sprintf( '<span %s>', genesis_attr( 'entry-tags' ) ) . $terms . '</span>';
break;
default:
$output = sprintf( '<span %s>', genesis_attr( 'entry-categories' ) ) . $terms . '</span>';
break;
}
else
$output = '<span class="terms">' . $terms . '</span>';
return apply_filters( 'genesis_post_terms_shortcode', $output, $terms, $atts );
}
// Show Portfolio Type hyperlinked terms (categories and tags)
add_filter( 'genesis_post_meta', 'sk_post_meta_filter' );
function sk_post_meta_filter( $post_meta ) {
if ( 'portfolio' == get_post_type() ) {
$post_meta = '[portfolio_terms taxonomy="portfolio_category"][portfolio_terms taxonomy="portfolio_tag" before="Tagged With: "]';
}
return $post_meta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment