Shortcode – Display CPT Tags

WordPress - General Shortcodes PHP

Snippet Overview

Shortcode – Display CPT Tags

// add_shortcode needs to return a string.
function tags_function() {
	$termsSecteur = get_the_terms( $post->ID , 'secteur' );
	if ( $termsSecteur != null ) {
		foreach ( $termsSecteur as $termsSecteur ) {
			$termsSecteur_link = get_term_link( $termsSecteur, 'secteur' );
			$return .= sprintf( '<a class="tag-secteur" href="%1$s">%2$s</a>', $termsSecteur_link, $termsSecteur->name );
			unset( $termsSecteur );
		}
	}
	return $return;
}
add_shortcode( 'list_tags', 'tags_function' );
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply