You can use this for single category name with link:
$category = get_the_category();
echo '<a href="'.get_category_link($category[0]->cat_ID).'"><img src="'.$category[0]->cat_name.'" alt="'.$category[0]->cat_name.'" /></a>';
Or for the loop you can try this:
foreach(get_the_category() as $category){
echo '<a href="'.get_category_link($category->cat_ID).'"><img src="'.$category->cat_name.'" alt="'.$category->cat_name.'" /></a>';
}
Related Posts:
- Display random categories on the front page (Finding and Editing Theme Functions)
- remove links from images using functions.php
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- How to add classes to images based on their categories?
- current_cat_ancestor Alternatives
- Add body class of category parent
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Php string not working in WordPress Functions.php (trying to fetch 1st category for each blog that post appears in the sidebar)
- Add class to Categories Widget
- How to Acheive the custom woocommerce category template
- How to add a rel attribute to images that contains their categories?
- How to set child post categories to parent post categories when updating parent post?
- Assign category using custom field?
- How To Get WordPress Categories Link List?
- Changing post category from dropdown
- Manipulate Output of wp_list_something: select menu instead of li’s
- Make Categories a Dropdown Menu in Media Library
- Programmatically Create Category and sub Category
- Attach parent category template to all subcategories
- Change Rating range in Link Manager
- exclude a category from a search on a specific page
- Get the category name outside of the loop in category.php
- Is it possible to change any of the HTML/URL returned from the_category()
- How to automatically remove links from WordPress Biographical Info?
- Custom HTML in specific category single page and its descendant categories
- Possible to display shortcode based on the category?
- Unset Category if other Category is unset during post transition
- Select pages by category
- Show Primary Category first when I display post categories
- How do I hide or remove ‘Category’ from wordpress breadcrumbs
- Ordering posts by publish date not working?
- How can I modify all existing tags while keeping the urls themselves?
- Add dynamic links in WordPress custom theme
- Categories as main menu items and subcategories as nested lists
- Can’t filter wp_get_attachment_link
- Get category URL for current post
- Need help “sanitizing” a custom function that pulls category slug into body class
- allow only one post in specific category
- How to obtain the recent posts without their content in an efficient way?
- Setting a default text for excerpts of a particular category
- Running script based on Category
- Remove a category from a post when saving a new post
- How to fix get_the_category function returning incorrect slug?
- Get arguments from URL
- Return category name with & Ampersand doesnt work
- javascript and css links not working on sever
- Access category within rss2_head hook?
- issue with if/elseif in_array inside foreach loop display only one post
- Randomizing wp_tag_cloud() in child theme
- Using Static HTML instead of the `home_url()` WP function
- add_filter to specific WooCommerce Category
- How to rewrite wordpress search to work on specific category
- Image loading function not working on archive.php template
- Exclude Category ID in function
- Problem with calling custom function in a foreach loop
- Specify multiple categories for custom post template – FATAL ERROR
- “All posts” in the category widget
- Get Attachment Category Name
- How to convert raw url to hyperlink?
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- Display ACF category image on archive and single template files
- Get slug of current category in functions.php
- Display a list of random terms from custom taxonomy with shortcode
- Change category display name function
- Display link to category over featured image
- Best practice to call a function from a button-link?
- Remove the ‘category’ url for one category type
- Custom Function.PHP Code Not Working on One Site
- Adding new Category does not refresh the backoffice
- How do i tweak my wp Post title base on category of the post
- how to remove a tag in the_category function
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- Menu and category highlighting for a single post
- Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
- i can’t use wordpress functions in ajax loaded php file
- Graphic before title – Specific Category
- require_once() Causing categories and tag pages on dashboard to not refrsh
- Disable links to images only if link is an image
- different body classes for each category
- How To Get WordPress Categories Last Update Date?
- How to Add A Rel Filter to All Links?
- Add gallery id to rel attribe of wp_get_attachment_link
- How to get tags and categories?
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- Removing all Category pages with one exception
- Vimeo video play button color function
- Get category of post inside save_post hook
- Redirect a list of URLs to another URL, using functions.php
- How to limit character length in BuddyPress function output [closed]
- Display tags that only appear in one category
- Auto Generated HTML source code formatting
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- get_template_directory() – references parent theme directory
- WordPress comment_form() does not display actual comments
- Is it possible to create a shortcode to link to a specific post/page where the tag is just an attribute?
- Get shortcode attribute value to another function
- Child theme style.css didn’t work properly but the Customize Additional CSS did [closed]
- List Most Read Posts from last 7 days (with custom post type and other meta queries)
- Integrating custom API for post content into Admin interface & Public Website [closed]