You don’t need to hook the dw_get_category()
function. Simply do it like this:
function dw_get_category() {
global $post;
$categories = get_the_category($post->ID);
if ( $categories ) {
foreach ($categories as $category) {
$dw_category_slug = $category->slug;
$dw_category_name = $category->name;
}
} else {
$dw_category_slug = 'utopia';
}
$dw_category = array('name' => $dw_category_name, 'slug' => $dw_category_slug);
return $dw_category;
}
Then call it like this:
$the_post_cats = dw_get_category();
echo 'Category: '.$the_post_cats['name'];
echo 'Slug: '.$the_post_cats['slug'];
Related Posts:
- How to load several hierarchical categories from functions.php
- Get rid of WordPress category, tag and author archives?
- How to add the category ID to admin page
- How to create a widgetized sidebar for every category dynamically?
- Send an email when custom post type category is changed
- Only show category to certain user levels without plugin
- what is the action hook code to supporting product category condition in single product page of woocommerce?
- List Categories of the Parent Category of the Current Category
- Prevent function from triggering again when post in specific category gets another category?
- exclude category from WordPress Form function
- Action hooks returning old category instead of new category
- wp_list_categories, Add class to all list items with children
- Remove “Parent” Selection When Adding/Editing Categories?
- Check is category parent or not from its ID
- How to show in search results posts with a particular tag in a particular category?
- How can I get an tag to wrap each ancestor that gets outputted in this condition?
- If category is in parent category?
- How to add custom script to the particular Product Category page
- How to remove the “+Add Category” button from the Category metabox?
- Hide posts of a certain category unless logged in
- If in category to be inside of a function
- Add title, post content, and category like add_post_meta and update_post_meta
- Rename Default Category (Uncategorized) Via a Function
- Check child/parent categories if exists
- Custom HTML in specific category single page and its descendant categories
- Getting URL of archive (category) page
- How to show only one category in breadcrumb navigation
- Query posts from category based on a filter most favorited
- Add tag parameter to category.php
- Random Featured Image Based on Category
- add slug beside name in Admin Category Checklists
- Change div background acording to the selected category
- How to access deleted term inside delete_product_cat action
- Filter WooCommerce archive pages by an additional category
- How to use wp_list_categories with plugin category?
- Redirect depending on category chosen
- How to add icon over specific thumb
- Change Default Content when Creating a Post based on Previous Category Choice
- How to add a custom thumbnail size for a specific category?
- Different size video display for category page (smaller) & detail page (larger)
- Get_term_meta() does not work with pre_get_posts()
- Code to display category-specific single.php is overriding normal single.php, too
- Loop Through Categories in Custom Field
- Function to list posts from current post’s category fails in WP 3.8
- Show only one category in main query, issues on tag page
- Modify functions.php to add a term ‘uses-theme’ set to theme name on post save
- Show parent-child relationship for categories in the wordpress admin
- How To Find Out WordPress Category Table in MYSQL?
- Trying to use add_action and do_action with parameters
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Category Specific Archive
- Is there a plugin that will completely remove the category system?
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- How to get only the last child of category slug?
- How to list only child categories?
- Show recent posts in menu?
- Cannot add / edit categories to a post anymore
- List archived posts by subcategory
- How to check category of of custom post type or not
- Set a them for all subset of category
- How to query post like normal search would do. within search.php page
- WordPress Get Posts from each category equally
- Unwanted Duplicate Product Categories in WooCommerce
- Override the WordPress core function wp_referer_field
- Why custom taxomony not showing when create a post?
- Return category name with & Ampersand doesnt work
- Single.php Category Post Count
- wp_list_categories with show_count, except for specific categories
- Show the amount of posts in a tag in a specific category has
- Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)
- Show 10 Sub Categories Per Parent Category Page?
- Conditional category & tag statement
- How to remove the category from post slug
- How to display posts from specific category using get_option function?
- How to detect /category and /tag base pages?
- can I ‘combine’ categories as a menu item?
- How to divide Subcategories into pages of parent category wordpress
- List taxonomy terms assigned to a post in hierarchical view
- Hide category name but show posts
- Issue passing action class to nested function. Admin Columns
- Count how many posts have a specified tag AND category
- Show the parent taxonomy by creating shortcode in woocommerce?
- Post List by category and under custom taxonomy
- Balance Tags to the_content Words Length
- How to create template for children category?
- Categories and Tags Conflict after Woocommerce Installation
- the_content() not showing full posts in category template
- Show parent category if there is no subcategory
- Add category links?
- Removing categories, Comments etc from posts?
- Add html word before category
- Problem importing categories and sub-categories
- how to ask if in two categorys inside if
- Add an Exclusive or featured tag line to article titles
- How to list out post category name and description in page
- Print child category slug nicename