• I am using this code in the footer of the site, which enables the user to be redirected back to the referring page once successfully logged in. This works well on page.php pages and single.php posts as well as on custom template pages. BUT when the user logs in using the link from a category.php page then he is redirected to a specific single.php post, which FYI is the first post of the blog.
    THIS GIVES A SIMPLE LOGIN AND LOGOUT URL

    <?php if(!is_user_logged_in()):?>
       <a href="<?php echo wp_login_url( get_permalink() ); ?>" title="Login">LOGIN</a>
       <?php elseif(is_user_logged_in()):?>
       <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">LOGOUT</a>
       <?php endif;?>

    HERE IS HOW MY CATEGORY.PHP LOOKS LIKE WITHOUT ALL THE JAZZ

    <?php get_header(); ?>
    <?php if(is_category( $cat )): ?>
        <div id="container">
        <h2 class="archive-title"><?php single_cat_title( '', true ); ?></h2>
        <div id="content">
    
        <?php while ( have_posts() ) : the_post(); ?>
        <div id="archive-class">
        <?php the_title();?>
        </div>
        <?php endwhile; ?>
        </div><!-- #content -->
        </div><!-- #container -->
    <?php endif;?>
    <?php get_footer(); ?>

    FYI, I am logged in as an Admin, I have set my permalinks as %POSTNAME% and the category url looks like https://somedomain.com/category/example-category/ What is happening here ?

  • The topic ‘login does not redirect back to category page, but takes to first blog post’ is closed to new replies.