Skip to content

Instantly share code, notes, and snippets.

@srikat srikat/functions.php
Last active Apr 16, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.