You are much too late in the page load sequence to redirect. You need to redirect before headers are sent to the browser. The template_redirect hook should be a pretty good option:
function redirect_cat_wpse_207298() {
if (is_category()) {
global $post;
wp_safe_redirect(get_permalink($post->ID));
die;
}
}
add_action('template_redirect','redirect_cat_wpse_207298');
Related Posts:
- Best Way to Redirect Category to Page and Hide Category
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Preventing index.php?category_name=something from redirecting
- Add forward slash on categories url (serve one version of a url)
- Multisite blog converting categories to subdomains
- Optimal way to redirect home page to category archive?
- Redirecting specific category posts to subdomain
- How to: 301 Redirect /category/ to /customname/
- How to? Redirect /category/sci-fi/ to /category/scifi/?
- Redirect category to first available child post
- Redirect category to url with /category
- Changing permalink from /postname/ to category/postname/
- WordPress category page redirects in .htaccess not working
- Why do my categories redirect?
- WP didn’t redirect to canonical category URL
- Sub Categories Keep Redirecting to Pages With Same Slugs
- redirecting from a general category page to another specific one
- Redirect single article permalink to paginated category page
- Automatically redirect a page to a category that share the same slug
- WordPress link to post links to category (loop)
- How to display post in custom file not in archive file?
- Use blog as base for tags and categories
- Category link redirect to custom template page instead of index.php?
- Redirect depending on category chosen
- Need help with major category and permalink re-organization
- Redirect Problems with Archive Page and GET variables
- OK to redirect the root WordPress category slug?
- How to prevent WordPress from redirecting single page to prefixed category archive with same name?
- Category pages redirecting to tab on Posts page grid
- Default URL for category dropdown select option
- WordPress Category url redirects to subdomain
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Paginations in Category Page Leads to Sample Pages
- htaccess redirect for all categories converted to tags now showing 404
- Page redirecting to category (IE only)
- Category Redirection Problem
- get all tags from category
- How can I add the featured image functionality to a custom taxonomy?
- WordPress and isotope filtering
- Check if current category has subcategories
- 5 blogs on one WordPress site
- Sticky Posts Not Sticking to Top of Category Archive
- How to exclude categories from recent posts, recent comments & category widgets?
- Exporting just posts of a specific category
- Select category in custom query
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Search by word, category, tag, author
- How to hide certain categories in wordpress dashboard?
- How to filter archives both by category and tag?
- How to retain the values from dropdown category lists after wrong form submission?
- How i can let users add notes to my posts
- Single_cat_title() print the title before text
- Sort posts by post_type in category.php template
- Why would in_category only return one post in a specific category?
- getting content from main domain to sub-domain using category and WP_Query
- Force a user’s posts category
- Checking for two categories in query_posts
- get_the_categories filter returns an empty array
- Show category to visitors in different name or different language without changing basic category
- How to get latest posts from each category in regular order
- menu using category and tags
- Have parent category contain only one post?
- wp e-commerce group product by category [closed]
- Limit get_categories to show each category once
- get parent category only
- “Item not updated” when try to change category properties
- How can I tell what category I’m in– in the header?
- new WP_Query all post in a category inside the loop
- How to display sticky or latest published post on the current category page it belongs to?
- Category tags with comma’s
- Trying to create a Categorised Index (archive?) to use as my Home Page
- Filter posts by categories ajax is showing nothing
- How to display child categories of all parent category within a singe loop?
- How can I add a class to displays a category?
- How to show only the name of one category above each posts in frontpage?
- WP_Query – using category__and when one of the categories is 0
- Multiple categories for one menu item?
- Hide categories from frontend, but not admin / post editor
- Exclude categories from homepage not longer working
- Post to inherit custom category background image from parent
- Related posts widget – category
- Editing Loop So It Targets Specific Tags?
- Header Link function not working. Problem with bloginfo()
- WordPress category filters as subcategories
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- Modifying category order
- Please tell how to stop the category from showing up on posts
- Editing categories crashes WordPress site
- Remove “category” from permalink with add_rewrite_rule
- Next and previous links category infinite loop
- show only terms from parent category
- Accessible Subcategory URL’s pages without using .php hack
- How to display total views of all posts of one category?
- Grouping parent categories into sections
- How to show “category” name?
- filter single_cat_title avoiding the breadcrumbs
- Category page with gallery for each post
- Search functionality with multiple categories
- How to define category ID in an array?
- how do I exclude a category foreach