Skip to content

Instantly share code, notes, and snippets.

@cutterkom
Last active September 20, 2020 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cutterkom/8baed06ed2295d8b8078 to your computer and use it in GitHub Desktop.
Save cutterkom/8baed06ed2295d8b8078 to your computer and use it in GitHub Desktop.
WordPress: Redirect from category.php to first post in category
function strytllr_redirect_from_story_to_first_slide(){
global $wp_query;
if( is_archive() && $wp_query->query('showposts=1&order=ASC') ){
the_post();
// Get permalink
$post_url = get_permalink();
// Redirect to post page
wp_redirect( $post_url );
}
}
add_action('template_redirect', 'strytllr_redirect_from_story_to_first_slide');
@harshdeepkaur097
Copy link

Hi, how do I implement it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment