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
- Get category ID from category slug (not working)
- How do I remove “Uncategorized” from posts with more than 1 category?
- Control term order on a per-post basis
- Changing Top Level Items into Radio Buttons in the Categories Meta Box?
- Custom post types with their own permalink structure
- How to create a widgetized sidebar for every category dynamically?
- Display the deepest child category from Category X (in loop)
- When using get_categories or similar, is it possible to filter results that contain certain Tags as well?
- Exclude subcategories from the url
- Select category in custom query
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Search by word, category, tag, author
- How to hide certain categories in wordpress dashboard?
- How to filter archives both by category and tag?
- Resolved – category-slug.php not working after wordpress migration
- How to retain the values from dropdown category lists after wrong form submission?
- How i can let users add notes to my posts
- Single_cat_title() print the title before text
- Sort posts by post_type in category.php template
- getting content from main domain to sub-domain using category and WP_Query
- editing fonts of category links from the_category() funtion
- Force a user’s posts category
- Checking for two categories in query_posts
- get_the_categories filter returns an empty array
- Show category to visitors in different name or different language without changing basic category
- How to get latest posts from each category in regular order
- limit a list of tags to one category [closed]
- How many categories can WordPress handle before performance suffers?
- Get sort order of product categories
- How to pull a list of posts in a category while exluding posts in subcategories of the category
- Exclude category from query
- How to loop custom post_type from (a) specific category(ies)?
- Showing HTML if Post is In Certain Taxonomy Term
- Add code to header based on category for specific posts?
- Can I prioritize post categories for choice for breadcrumb trail?
- Category List with custom urls
- Load the last post of a category
- create function to call category name and slug
- Disable Category Taxonomy
- A different permalink structure for different categories
- How to make product image inherit from category image
- Is it possible to set up blog categories without changing permalink structure
- How to display categories image in loop homepage WordPress
- How to “remove” WordPress categories UL and make the list loop in a horizontal line?
- How do I rewrite a single category link to point to a custom page?
- Add subcategories posts to the counts column at the admin’s categories list
- Display one post on category.php: Wrong featured image
- Display related posts with same category or same tag return blank
- Get posts from 2 or more categories
- date.php shows all posts. how to fix it?
- Help with Wp + Mixitup code
- How can I get this code to only output one link?
- How to get Woocomerce categories count
- show posts from some category and sort by advance custom field