Here is an example of how you can do it with your code, using the category name as the class name:
<?php
// category link
$categories = get_the_category();
if ( ! empty( $categories ) ) {
echo '<a class="' .esc_html( $categories[0]->name ) . '" href="' . esc_url( get_category_link( $categories[0]->term_id )
) . '">' . esc_html( $categories[0]->name ) . '</a>';
}
// category link
?>
Related Posts:
- WordPress Theme variables scope
- why is translation not working on theme?
- How to export/import theme customizer settings?
- Check php version before theme activation
- Separate WordPress themes for each category page
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- How to get the registered sidebar’s name by its id?
- One button to change all settings in theme customizer?
- Replacing mysql_real_escape_string in WordPress theme
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Activate different theme for temporary preview
- Nice scroll to wordpress
- Twitter feed is showing blank in WP site [closed]
- Design view breaking on Pages
- How do I hardcode a WordPress shortcode into my theme?
- Passing array in add_option()
- Create a quick start wordpress installation [closed]
- How should I best target dynamically served content?
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- Can’t load WP function into external function
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- Show full posts in archive
- WordPress: Access a plugin from within a theme
- Getting error when trying to implement site-wide breadcrumbs in Twentytwentyone Theme [closed]
- Reconfiguring WordPress site
- Customizer: active_callback and sanitize_callback incompatibility?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Custom Theme’s “Preview Changes” Doesn’t Work for Previously Published Posts
- How to change theme programmatically from a external application?
- What does this mean in wordpress? Easy question
- WordPress Customizer Default Image
- Do I have anything to worry about when switching to a default theme to test for plugin conflictions?
- Why in my theme I can’t see all the statics content under the posts?
- How to add the sidebar to all the pages except the home page? [closed]
- Header not properly displaying on archive.php
- Save Custom CSS file in the upload folder dynamically?
- Design with Elementor and code the rest?
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- home.php show blog posts as grid view
- blank white page when post/update/change option etc
- How to Update an old theme for the latest wordpress version
- Problems clearing cache
- Override index with a custom PHP page
- Implementing custom tag/tax pages
- Randomize Color Scheme Selection in Theme
- Accidentally deleted php code in WordPress website [closed]
- ‘Bones’ theme: Load stock scripts in footer instead of header?
- How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
- Why in this WordPress theme I can’t see the Main Menu?
- Displaying Slider in Front Page (home) using Customizr Theme
- call a string/function from database
- Commas in Tag Cloud
- Is there a (offical) way for a theme to deactivate itself and show a message in admin?
- WordPress redirects page query parameter in URL
- Publish button now showing content after saving
- How to put search bar & logo in the “primary navigation” storefront theme?
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- error_log PHP error log found. This file must not be in the production version of the theme. (wordpress theme check plugin)
- I am having issue in divi woocomerce checkout module. (DIVI theme)
- How do I use an iFrame for my header in WordPress twenty seventeen?
- Not able to remove caption shortcode from the content
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- File from parent theme imported to child theme doesn’t work – any ideas?
- How to use data URL in WordPress?
- wordpress email checker on domain
- Unable to retrieve get_author_posts_url
- Display post date also if the date it’s the same for each post
- Force Sidebar on Full Width page
- Invalid Argument foreach
- How can I render more than multiple posts on template-parts with post formats
- Add the shortcodes from the enfold theme to the other theme
- WordPress child theme, creating a custom php template page
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- Menu to the right of screen on desktop using Bootstrap 4
- style.min.css code issue
- Beginner Developing Theme with Bootstrap – NavMenu question
- Local WordPress from Git repo, where to set document root?
- user update profile for custom code
- Create a custom theme-specific page, invisible in the admin-panel?
- Editing existing pre-created menus in PHP
- Two theme locations for two menus, but only one is showing up
- Image not displayed
- Include a php file that is above WP installation hierarchically?
- Using existing widget code! [closed]
- WordPress Website Featured Image Replacement Issue
- doubled content
- Themes with variable width or single columns? I want to display source code
- .htaccess on multisite and roots theme?
- Move wordpress sidebar on homepage up to new position
- How can I print out a single stylesheet or javascript link?
- Catchable fatal error in appcloud free theme by Tokokoo
- Errors while Loading Most Recent Version of jQuery
- WordPress menu links with images & class selection
- How to create and add js and css file when server is not on my PC?
- How to remove the intro animation which appears during the load up of some WordPress themes? [closed]
- How to store the_post_thumbnail() value in a variable
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- a problem in class in class-wp-hook.php
- Using Featured Image as Hero Background in Word Press
- Font Awesome Icons as squares [closed]