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
- Query posts that have all the specified tags
- add query string to all pages after user logged in
- Multiple Parent Category URLs
- How can I show page per category in wordpress? (Yes, category by page!)
- has_category not working correctly
- How to get most recent categories – categories whose most recent posts published
- Back to category link
- Custom Woocommerce Category view
- Category Template – to be editable from the backend?
- Random post order into Category Pages
- How do I add and display a custom image field to a category? [duplicate]
- comments_number fails to print
- Chained drop-down menu for custom taxonomy using chained.js
- How to display the posts belonging to a paticular category
- Do something when user creates post (that’s pending)
- get posts from 2 categories. (2 posts)
- WordPress 3.5 how to determine if user is on category listing or category edit screen?
- Why Pagination is not working on Category.php
- Javascript code for Category
- Display post content from category name using ajax
- How to assign different categories to pages in wordpress?
- Display only one level subcategory in wordpress
- How to get child category list post in one template?
- Display all subcategories for a product category in woocommerce
- How to display a linked category name with get_the_category
- why is the delete option missing from just one category?
- Call function on a single page
- Not able to display category link and name [closed]
- How to prevent uppercasing of menu titles
- Only show sub-category
- how to ask if in two categorys inside if
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- Help Me “in_category” with echo? [closed]
- How to control order when displaying child categories
- Can i know if it is Category first page or 5th?
- Displaying categories
- Country Ways Content Show
- Broken category styling
- How can i hide the authors box from a specific set of categories and post types?
- Do not show all post from all categories, just show posts from category in current loop
- 2 Categories using same template but one has a problem? [closed]
- How to prevent page re-sizing for mobile browsers [closed]
- Displaying categories and subcategories without link
- Exclude posts from certain category breaks custom pagination
- IF have_posts contains posts from a certain category
- Make a category my homepage
- Excluding cateory not working on my site. how to solve this? [closed]
- Get all first images of posts in same category
- Replace the post count on wp_list_categories with “Has Posts” instead of number and “No Posts” if none
- have_posts is empty on category.php
- Call a function with href
- WooCommerce Product Search Error
- Custom permalinks structure