Redirecting category link to first child post

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');

Leave a Comment