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 Codex
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 ...
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
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' ...
WP Engine
How to Get a WordPress Category Name Without the Link - WPMU DEV
March 11, 2022 - Have you ever needed to display the name of your current category without a link? In this article, we'll show you how to do that by adding a few lines of code.
Stack Overflow
php - Get specific categories in wordpress for current post - Stack Overflow
I have been trying to achieve the following without luck. I have the next categories in wordpress: Book (level 1) Chapter 1 (level 2) Article 1 (leve 3) Article 2 (leve 3) ...
Envato Forums
Display a list of all categories on a page (Wordpress) - Envato Forums
June 24, 2013 - Hi everyone, I want to know how to display a list of all categories in my (wordpress) website on one page. I’d like to display a list of links to all my categories in a on a page WITHOUT showing the posts under categories. I have large list of categories and that´s why I´m asking for this.