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

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

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  braddalton 6 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #93451

    martialwarrior
    Participant
    Post count: 38

    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/
    #93484

    braddalton
    Participant
    Post count: 9730

    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


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.