• Resolved amandasan

    (@amandasan)


    Hi- I’m fairly new at WordPress, and I’m working on a site for a client that wants a user to login/register after they click the “continue reading” button, basically they can’t read the rest of the blog post unless they are logged in. I have the continue reading button working, but I’m not quite sure how I can force users to login after clicking it. I searched for this issue and I could only find things about making the continue reading button work.. Thank you in advance for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Well, one thing you could do is hide the content after a certain point if they aren’t logged in, and instead show a login box. Or optionally display an excerpt for those not logged in, and the content for those who are.

    For example:

    <?php if(is_user_logged_in()): ?>
    <?php the_content(); ?>
    
    <?php else: ?>
    <?php the_excerpt(); ?>
    
    <b>Please log in to view the rest of this article</b>
    
    <ul id="page-login">
    	<li>			
    
    <form action="<?php bloginfo('url') ?>/wp-login.php" method="post">				<p>
    <label for="log">
    <input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22" /> Username</label><br />
    <label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br />
    <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br />
    <input type="hidden" name="redirect_to" value="https://www.pagetoredirectto.com" />
    
    <input type="submit" name="submit" value="Login" class="button" />				</p>								</form>
    </li>
    <li><a href="<?php bloginfo('url') ?>/wp-register.php">Register</a></li>
    <li><a href="<?php bloginfo('url') ?>/wp-login.php?action=lostpassword">Recover password</a></li>
    </ul></div>
    <? endif; ?>

    That checks if the user is logged in. If so it shows the content. Otherwise it shows the excerpt and a log in box. The only thing you’d have to change there is this line: <input type=”hidden” name=”redirect_to” value=”https://www.pagetoredirectto.com&#8221; /> I can’t remember how to tell it to redirect to the same page they were on when logging in, rather than taking them to the dashboard.

    Hope that helps!

    Thread Starter amandasan

    (@amandasan)

    That worked great! I modified it- put a link to the login page after <?php else ?> – and I got what I needed. Thanks so much for your help ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Login to Continue Reading’ is closed to new replies.