Just use $category->slug
instead of $category->cat_name
. Slugs are already lowercase and with dashes instead of spaces.
Related Posts:
- Display random categories on the front page (Finding and Editing Theme Functions)
- 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?
- Adding body class when post contains a specific shortcode
- 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
- List of Body Classes Generated by body_class()
- 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()
- 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?
- Categories as main menu items and subcategories as nested lists
- Get category URL for current post
- 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?
- Return category name with & Ampersand doesnt work
- 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
- 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
- Add a class to post if it has been recently updated
- 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
- 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
- Menu and category highlighting for a single post
- 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
- different body classes for each category
- How To Get WordPress Categories Last Update Date?
- How to get tags and categories?
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Removing all Category pages with one exception
- Get category of post inside save_post hook
- Remove Actions/Filters added via Anonymous Functions
- Generating Responsive Background Image Sizes in PHP
- Override a class function to include a custom template
- How to auto-update child posts whenever the parent post is updated?
- the_post_thumbnail fallback using hooks
- How to detect first visit of a user?
- Remove “Parent” Selection When Adding/Editing Categories?
- Override woocommerce wc-class function
- Is possible add icon in title posts only in specific tag?
- Wp_schedule_event functions.php
- Can’t generate thumbnail images
- Showing custom post type categories in the menu
- Custom HTML markup
- Functions Error: Impacting Galleries
- How to cut off question mark in url with functions.php
- Theme JS is available but theme CSS isn’t
- Genesis Framework: How to exclude a specific author from archive custom loop
- How to create a shortcode out of a php function
- Is it possible to use add_filter in an included file in the child theme’s functions.php?
- Insert Content Before div#main from the functions.php File
- Insert function insde body tag
- I would like single.php to act just like index.php
- Does WordPress has an automatic link parse function?
- How do I trigger WP CLI DB export using a PHP function?
- Redirect specific author posts to another url
- How to retrieve image IDs from shortcode content?
- WordPress – Custom Nav menu for logged in users – Shopkeeper theme
- Change post count on tag/terms pages to 10
- Fatal error after changes to functions.php, even with original file