$post_type = $post->post_type;
                $taxonomies = get_object_taxonomies( $post_type, 'objects' );
                foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){ 
                    $terms = get_the_terms( $post->ID, $taxonomy_slug ); 
                    if ( ! empty( $terms ) ) {
                            $termname = esc_html( $terms[0]->name );
                            $termslug = esc_html( $terms[0]->slug );
                            $termlink = get_term_link($terms[0]);
                            $parent = $terms[0]->parent;
                            $parentlink = get_term_link($parent);
                            $parentterm = get_term( $parent, $taxonomy_slug );
                            $parentname = $parentterm->name;
                    }
                }
if( !empty( $parentlink) ){echo '<a href="' . $parentlink . '">' . $parentname . '</a> ';}