You need to get the category object and then use a foreach loop to build your list.
This should work for you:
<?php $categories = get_categories(); ?>
<nav>
<?php foreach ($categories as $category):?>
<a href="<?php echo get_category_link($category->term_id); ?>" class="nav-link" id="<?php echo $category->name;?>"><?php echo $category->name;?></a>
<?php endforeach; ?>
</nav>
Answer from Hiram Hibbard on Stack OverflowWordpress
get_category_link() – Function | Developer.WordPress.org
You must log in to vote on the ... log in to vote on the helpfulness of this note ... <?php // Get the ID of a given category $category_id = get_cat_ID( 'Category Name' ); // Get the URL of this category $category_link = get_category_link( $category_id ); ?> <!-- Print a link to ...
WisdmLabs
How To Create A Link To Current Category In WordPress
April 7, 2014 - <a href=”<?php echo $category_link ?>” title=”<?php echo $category_name ?>” > <?php echo $category_name ?> </a>[/pre]
WPExplorer
How to Link to the Current Category in WordPress
September 26, 2023 - This tutorial will show you how to link to the current category for the post you are viewing in WordPress using a code snippet.
Wordpress
get_the_category() – Function | Developer.WordPress.org
You must log in to vote on the helpfulness of this noteVote results for this note: 9You must log in to vote on the helpfulness of this note · Show All Categories as Links This outputs all the categories assigned to the post as links. Must be used inside the loop.
Wordpress
Linking Posts Pages and Categories « WordPress Codex
When doing so, you may safely omit ... and link to the target with a full path: ... The leading slash means "At the very top of this domain is a directory named wordpress, and inside this directory is a file named index.php". ... The lack of a leading slash means "Inside the current directory ...
WPMU DEV Blog
How to Get a WordPress Category Name Without the Link - WPMU DEV
March 11, 2022 - ' '; } ?> category. I will also put <strong> tags around it to make it bold, so the complete line I am inserting will look like this: <strong>This post is from the <?php foreach((get_the_category()) as $category) { echo $category->cat_name .
Wordpress
get_categories() – Function | Developer.WordPress.org
List Categories and Descriptions This example will list, in alphabetic order, all categories presented as links to the corresponding category archive. Each category description is listed after the category link. <?php $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC' ...
WPBeginner
How to Display Category Descriptions in WordPress
December 4, 2024 - Do you want to display category descriptions on your WordPress site? Learn how to easily add and display category descriptions in WordPress.
CodexWorld
How to Get Post Category Name and URL in WordPress - CodexWorld
November 20, 2015 - WordPress Get Post Category - Display category of the post in WordPress. Get the current post category name, slug, or URL in WordPress.