-
-
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
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 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