Created
June 17, 2015 05:24
-
-
Save moabi/f207c7a0c5eb9310f07a to your computer and use it in GitHub Desktop.
Redirect if only one post in category - wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stf_redirect_to_post(){ | |
global $wp_query; | |
if( is_archive() && $wp_query->post_count == 1 ){ | |
the_post(); | |
$post_url = get_permalink(); | |
// Redirect to post page | |
wp_redirect( $post_url ); | |
} | |
} | |
add_action('template_redirect', 'stf_redirect_to_post'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment