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 a WordPress Expert

Get hourly and project based theme customization, theme tweaks, and development help from an experienced Kelowna WordPress developer.  We’ve been building WordPress websites full-time for over a decade. We can help you.