Skip to main content
added 238 characters in body
Source Link
Jacob Peattie
  • 43.9k
  • 10
  • 49
  • 62

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 );
?>

Pass the category id into get_category_link():

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

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 );
?>
Source Link
Jacob Peattie
  • 43.9k
  • 10
  • 49
  • 62

Pass the category id into get_category_link():

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