get_* functions are return functions. They don't actually print anything. Given your code example, all you should need is an echo statement:

<?php 
global $post;
$category = reset(get_the_category($post->ID));
$category_id = $category->cat_ID;
?>

<a class="button" href="<?php echo get_category_link( $category_id ); ?>">&larr; Back to Portfolio</a>

ALTERNATIVE: The best way of doing this would be to keep everything in your loop for reuse in single or archive views, combined with the use of wp_get_post_categories. This is untested, but it should get you started with a general-use method of listing categories associated with a given post or set of posts:

<?php
if(have_posts()) : while(have_posts()) : the_post();
    $cats = wp_get_post_categories($post->ID);
    if($cats) : foreach($cats as $cat) : $category = get_category($cat);
    ?>
    <a class="button" href="<?php echo get_category_link($category->cat_ID); ?>">&larr; <?php echo $category->name ?></a>
    <?php
    endforeach;endif;
endwhile;endif;
?>
Answer from maiorano84 on Stack Overflow
🌐
WordPress
developer.wordpress.org › reference › functions › get_category_link
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 ...
🌐
Stack Overflow
stackoverflow.com › questions › 20039661 › get-current-category-link
php - Get current category link - Stack Overflow

get_* functions are return functions. They don't actually print anything. Given your code example, all you should need is an echo statement:

<?php 
global $post;
$category = reset(get_the_category($post->ID));
$category_id = $category->cat_ID;
?>

<a class="button" href="<?php echo get_category_link( $category_id ); ?>">&larr; Back to Portfolio</a>

ALTERNATIVE: The best way of doing this would be to keep everything in your loop for reuse in single or archive views, combined with the use of wp_get_post_categories. This is untested, but it should get you started with a general-use method of listing categories associated with a given post or set of posts:

<?php
if(have_posts()) : while(have_posts()) : the_post();
    $cats = wp_get_post_categories($post->ID);
    if($cats) : foreach($cats as $cat) : $category = get_category($cat);
    ?>
    <a class="button" href="<?php echo get_category_link($category->cat_ID); ?>">&larr; <?php echo $category->name ?></a>
    <?php
    endforeach;endif;
endwhile;endif;
?>
Answer from maiorano84 on stackoverflow.com
Videos
April 24, 2022
1.13K
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 245303 › print-current-post-category-during-wp-query
wp query - Print current post category during WP_Query - WordPress Development Stack Exchange

You are using the get_the_terms() but this function is used to get the custom taxonomies.

Use the function get_the_category(); inside the WordPress loop and pass the get_the_ID() function which will get the current post ID in the loop.

get_the_category(get_the_ID());

                <?php
                  $args = array(
                    'post_type' => 'work',
                    'posts_per_page' => '9'
                  );
                  $work_loop = new WP_Query( $args );
                  if ( $work_loop->have_posts() ) :
                    while ( $work_loop->have_posts() ) : $work_loop->the_post();
                      // Set variables
                        $cat_ids                = get_the_ID();
                        $cat_names_array        = get_the_category($ids);
                        $work_category           = get_the_category( get_the_ID() );
                        $work_title             = get_field( 'work_title' );
                        $work_main_image        = get_field( 'work_main_image' );
                        $work_link              = get_field( 'work_title' );
                        $work_about             = get_field( 'work_about' );
                        // $work_category = get_the_terms( the_post()->ID, 'taxonomy' );
                      // Output
                      ?>
                      <a href="<?php echo $work_main_image['url']; ?>" class="single_item link <?php foreach ( $work_category as $key => $value) { echo $value->category_nicename . " "; } ?> col-md-4 col-sm-6 wow fadeInUp" data-wow-delay="0.3s">
                        <img src="<?php echo $work_main_image['url']; ?>" alt=""> 
                    </a>
                    <?php
                      endwhile;
                    wp_reset_postdata();
                  endif; 
                ?>

Cheers :)

Answer from Syed Fakhar Abbas on wordpress.stackexchange.com
🌐
WordPress
developer.wordpress.org › reference › functions › get_the_category
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.
🌐
WPExplorer
wpexplorer.com › tutorials › how to link to the current category in wordpress
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.
🌐
Stack Overflow
stackoverflow.com › questions › 22849124 › how-to-print-the-link-of-a-category-into-the-href-of-an-anchor-tag-in-wordpre
php - How to print the link of a category into the href="" of an anchor tag in Wordpress? - Stack Overflow

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 stackoverflow.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 219954 › how-do-i-get-the-category-url-from-get-the-category
categories - How do I get the category URL from get_the_category? - WordPress Development Stack Exchange

Use:

get_category_link( $category_id );

See:

https://codex.wordpress.org/Function_Reference/get_category_link

In your specific case:

<?php
global $post;
$categories = get_the_category();

    foreach ($categories as $category) :

       $exclude = get_the_ID();
       $posts = get_posts('posts_per_page=4&category='. $category->term_id);

        foreach($posts as $post) :
         if( $exclude != get_the_ID() ) { ?>

                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="post c-1"> Link to actual post</a>

    <?php } endforeach; ?>

<a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>" title="View all" class="btn border"><i class="i-right-double-arrow"></i> View all <?php echo $category->name; ?></a>
<?php  endforeach; wp_reset_postdata(); ?>
Answer from Adam on wordpress.stackexchange.com
🌐
Stack Overflow
stackoverflow.com › questions › 14816552 › wordpress-get-category-link
php - Wordpress get category link - Stack Overflow

Sounds like you may want get_category_link - something like:

$categories = get_categories();
foreach ($categories as $cat) {
    $category_link = get_category_link($cat->cat_ID);
    echo '<a href="' . esc_url($category_link) . '" title="' . esc_attr($cat->name) . '">' . esc_html($cat->name) . '</a>';
}

should print out the links to the categories for you.

Answer from anotherthink on stackoverflow.com
Find elsewhere
🌐
WordPress Codex
codex.wordpress.org › Linking_Posts_Pages_and_Categories
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 ...
🌐
WisdmLabs
wisdmlabs.com › home › wordpress basics › how to create a link to current category in wordpress
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]
🌐
Stack Overflow
stackoverflow.com › questions › 8829632 › get-current-category-id-of-the-active-page
php - Get current category ID of the active page - Stack Overflow

If it is a category page,you can get id of current category by:

$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;

If you want to get category id of any particular category on any page, try using :

$category_id = get_cat_ID('Category Name');
Answer from Ram Mehar Deswal on stackoverflow.com
🌐
WordPress
developer.wordpress.org › reference › functions › get_categories
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' ...
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 131749 › display-current-category-title-on-category-page
php - Display current category title on category page - WordPress Development Stack Exchange

On a category page, you can use the function single_cat_title(), or the more generic single_term_title(). These functions pull from the global $wp_query object, via get_queried_object().

Answer from Milo on wordpress.stackexchange.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 274018 › get-category-url-for-current-post
functions - Get category URL for current post - WordPress Development Stack Exchange

Pass the category id into get_category_link():

<?php
$category = get_the_category();
$link = get_category_link( $category[0]->term_id );
?>

Update Outputting in template:

<?php
$category = get_the_category();
$first_category = $category[0];
echo sprintf( '<a href="%s">%s</a>', get_category_link( $first_category ), $first_category->name );
?>
Answer from Jacob Peattie on wordpress.stackexchange.com
🌐
Stack Overflow
stackoverflow.com › questions › 1735953 › display-link-to-category-in-wordpress
Display Link to Category in Wordpress? - Stack Overflow

If you want to do this on post page you can add something like the following to your single.php file of your theme.

<div class="meta">Posted in: <span><?php the_category(', ') ?> </span></div>
Answer from gbennett on stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 39704715 › how-to-display-all-categories-in-wordpress
how to display all categories in wordpress? - Stack Overflow

In the code you gave us you are selected the categories selected for the specific post get_the_ID() is doing that part. However you would be best off using another function get_categories() https://developer.wordpress.org/reference/functions/get_categories/ which you would do like so:

$categories = get_categories();
foreach($categories as $category) {
   echo '<div class="col-md-4"><a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></div>';
}

You can also pass through arguments to be more specific (if needed) - see https://developer.wordpress.org/reference/functions/get_terms/ for details on what you can pass through

Answer from Simon Pollard on stackoverflow.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 243856 › how-to-get-current-category
php - How to get current category - WordPress Development Stack Exchange

You can use get_queried_object(), which will return category object.

See documentation:

https://codex.wordpress.org/Function_Reference/get_queried_object

Answer from Aniruddha Gawade on wordpress.stackexchange.com