Link To Current Category In WordPress

Came across an article that was well explained me of how to link to current category.

This technique is very useful when your WordPress theme doesn’t support Breadcrumb functionality due to server incapability to generate link with Post name based Permalink structure setting, or any other issues that prevent you to show breadcrumbs by default in your WordPress website.

So what I did is just to copy this function:

<?php
$get_cat        = get_the_category();
$first_cat      = $get_cat[0];
$category_name  = $first_cat->cat_name;
$category_link  = get_category_link( $first_cat->cat_ID ); ?>
<a href="<?php echo esc_url( $category_link ); ?>" title="<?php echo esc_attr( $category_name ); ?>"><?php echo esc_html( $category_name ); ?></a>

and paste it to my single.php file. It will display a link to the first category of your post. You can place this code in any theme template file, even outside the loop.

As simple as that! In the source article you will find some other more options to display category link.

Icons made by Freepik from www.flaticon.com