• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to redirect to single post page if there is one post in category/tag

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to redirect to single post page if there is one post in category/tag

This topic is: resolved

Tagged: redirect to single post

  • This topic has 3 replies, 2 voices, and was last updated 11 years, 2 months ago by martialwarrior.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • March 4, 2014 at 7:20 pm #93451
    martialwarrior
    Participant

    I want to know how to redirect to single post/page if there is one post in a category. I was told about this code snippet, put I am not sure where in the Functions PHP for the Blissful Theme the snippet should go, as when I put it where I think it should go, it breaks the site. Please advise exactly where to put the snippet. Thank you!

    function stf_redirect_to_post(){
    global $wp_query;

    // If there is one post on archive page
    if( is_archive() && $wp_query->post_count == 1 ){
    // Setup post data
    the_post();
    // Get permalink
    $post_url = get_permalink();
    // Redirect to post page
    wp_redirect( $post_url );
    }

    } add_action('template_redirect', 'stf_redirect_to_post');

    http://usamahof.com/
    March 5, 2014 at 12:32 am #93484
    Brad Dalton
    Participant

    Please copy ALL the code from the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++

    https://gist.github.com/braddalton/7633999eb91c604b39db


    Tutorials for StudioPress Themes.

    April 19, 2015 at 10:26 am #148418
    martialwarrior
    Participant

    I am using the Whitespace Pro Theme on JohnNatividad.com and want redirect to single post page if there is one post in category/tag but when I use the code snippet below I get a redirect loop. What do I need to do to fix this?

    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');

    April 19, 2015 at 10:36 am #148420
    martialwarrior
    Participant

    I got it fixed!!!

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘How to redirect to single post page if there is one post in category/tag’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble