Display Parent Taxonomy Link in CPT

Experimenting with custom WordPress taxonomies. Automatically display the name of the parent taxonomy, and link to it - from within a child post of that taxonomy.

In a Custom Post Type (ie: Lesson) and in that lesson template, you want to display the name of the taxonomy that it’s in – let’s say a Module.

Just the name of the parent taxonomy

// this one works to display the name of the current posts taxonomy title
add_action( 'genesis_before_sidebar_widget_area', 'parent_module_link' );
function parent_module_link () {
	$terms = get_the_terms( $post->ID , 'module' );
		foreach ( $terms as $term ) {
		echo '<h4>' . $term->name . '</h4>';
		}
	}

The name of the parent taxonomy linking back to its archive page

//This will display a link and name of the parent module
add_action( 'genesis_before_sidebar_widget_area', 'parent_module_link' );
function parent_module_link () {
    $terms = get_the_terms( $post->ID , 'module' ); 
        foreach ( $terms as $term ) {
            $term_link = get_term_link( $term, 'module' );
            if( is_wp_error( $term_link ) )
            continue;
            echo '<h4><a href="' . $term_link . '">' . $term->name . '</a></h4>';
        } 
}<

Hire WordPress Experts at Codeable.

The only WordPress exclusive freelancer platform that connects thousands of customers with the top WordPress freelance experts to work on projects of any size. 

Free estimate • No obligation to hire • 100% risk-free