Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created March 5, 2014 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/7633999eb91c604b39db to your computer and use it in GitHub Desktop.
Save braddalton/7633999eb91c604b39db to your computer and use it in GitHub Desktop.
Redirects Any Category, Tag or Other Archive Page To The Single Posts When Only One Post In Archive
function redirect_to_single_post(){
global $wp_query;
if( is_archive() && $wp_query->post_count == 1 ):
the_post();
$post_url = get_permalink();
wp_redirect( $post_url );
endif;
}
add_action('template_redirect', 'redirect_to_single_post');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment