You can use get_category_link() for that:
$allCat = get_the_category();
if( ! empty( $allCat ) ){
$lastCat = array_reverse( $allCat );
$last_cat_link = get_category_link( $lastCat[0] );
if( ! is_wp_error( $last_cat_link ) ){
echo '<a href="' . $last_cat_link . '">' . $lastCat[0]->name . '</a>';
}
}
https://developer.wordpress.org/reference/functions/get_category_link/
Related Posts:
- Category links suddenly started giving 404 errors
- Return array of categories to php function
- Listing all posts from current category on page
- Display WooCommerce product categories in a 4 columns custom menu [closed]
- Show post only if match all categories
- Dropdown category filter
- Any way to assign Post Categories and Tags to Links?
- Is it possible to select and edit the way the most recent post from a certain category is displayed on the page?
- How to enable category hierarchy for links?
- Resort get_categories
- Combining post categories and link categories?
- Displaying a full post instead of a slug per category?
- Link Attachment Image to Category
- Class active for Archive link – looped out
- Why do my categories redirect?
- Get category url in loop
- Older entries link within category page
- Style category link depending on category ID
- How to use an array of categories as a dropdown?
- Create menu locations for each category in wordpress
- Use premade array as categories in wp_query?
- Array: What is this value based on?
- Get paged category link programmatically
- How to get an array with all categories and corresponding names?
- List a maximum of ‘x’ product categories with qty of ‘y’ in each column
- Need to echo category id in multi-dimensional array
- Getting Category Children
- How to not display a category post on blog page?
- Link from navbar to categories
- I need to exclude from a query a category and a few custom taxonomies
- javascripts files not linking to my category slugs?
- wp_insert_link not working
- How to list posts from a sub-category that is listed in a parent category (more details below)?
- Show Subcategory Name Instead of Parent Category
- Link For Portfolio Categories
- Cant get unique_array() work on get_the_category() foreach loop
- How to get the link of all categories
- Matching usermeta at registration to categories of content
- Featured image for links and categories
- Categories as selectable links on submission form
- How to change category id on get_posts array
- Displaying categories and subcategories without link
- How to get category slug link? ( include parent categories)
- How to define category ID in an array?
- Order Categories by Character Count
- how do I exclude a category foreach
- Individual rss feed entry length for categories?
- Share one taxonomy across multiple blogs in 3.0 [duplicate]
- 404 Error On Category and Tags Pages
- Allow duplicate permalink slugs for posts in different categories
- Make all subcategories use the template of its category parent?
- Listing Category ‘child_of’ by slug rather than ID
- Exclude certain category from latest updates
- Hide Category from Blog?
- Dropdown with category selection
- Admin Panel – Disable Moving Selected Terms To Top of Metabox
- cat_is_ancestor_of() for custom taxonomies
- Category and tag with same name
- How to create non-unique sub-category slugs?
- Loop with Dynamic Categories
- How to display parent category name and link for custom breadcrumb
- Automatically select categories on new post based on GET value
- Exporting just posts of a specific category
- How to display only the parent category in the permalink
- How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?
- If a post has two categories with different permissions, what will happen? [closed]
- get only sub category ID
- Display categories inline
- Filter out posts before display category count
- How to show in search results posts with a particular tag in a particular category?
- Category vs Tag vs Table
- Add a specific category at a specific place to the menu that uses wp_list_pages
- How to find the number of Tags a post has?
- Multiple menu items highlighted
- Categories not working – 404 Not found error
- How to not treat categories as tags in feeds
- Add title, post content, and category like add_post_meta and update_post_meta
- wordpress wp_list_categories
- New Theme creation
- Custom order categories in admin dashboard
- How to create button to direct to certain category
- Group listed elements by category
- Editing Category Pages
- Display tags from specific category in select fields
- Highlight wp_nav_menu when category is selected
- woocommerce product category tabs [closed]
- Taxonomy name repeating when showing 2 posts from each category
- How to change category and year archive permalinks/rewrite rules?
- The Category page shows all the posts, without differentiating by categories
- Get link which associated with a specific category and tag
- How to disable default category linkbuilding?
- Category param redirect to post type archive
- batch adding posts to a category based on matching regex for title with SQL
- How to assign posts without any category to the default category
- Show only first category name in RSS?
- Show parent category in URL of subcategory archive page
- Filter $cpt categories to omit certain category
- Yearly Archive for Categories with dropdown
- Display Posts Loop for each parent and for each Child
- get_categories listing foreach with children