WordPress.org

Support

Support » Plugins and Hacks » [Resolved] A plugin to redirect user if there's only 1 post in category/tag page ?

[Resolved] A plugin to redirect user if there's only 1 post in category/tag page ?

  • Hi,

    Is there a plugin that allows me to redirect users if there’s only 1 post in category/tag page ? I mean redirect them directly to this single post.

Viewing 1 replies (of 1 total)
  • Sure, but there is a better way to do that !
    Simply paste this into your functions.php file (located in your theme folder)

    function redirect_to_post(){
        global $wp_query;
        if( is_archive() && $wp_query->post_count == 1 ){
            the_post();
            $post_url = get_permalink();
            wp_redirect( $post_url );
        }
    } add_action('template_redirect', 'redirect_to_post');

    Then all the users will be redirected to the single post found in any category/tag page 😉

    Cheers

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] A plugin to redirect user if there's only 1 post in category/tag page ?’ is closed to new replies.
Skip to toolbar