Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Site registration to prompt on single post pages WordPress

  • SOLVED

I'd like to have my site require users to be logged in when trying to view single post information. If they aren't logged in, they would be prompted by a login/registration screen, then redirected to the post they were trying to access. Does anyone out there have a solution to handle this?

Answers (2)

2011-05-24

Ivaylo Draganov answers:

This is actually very simple to achieve. Here it is for the default theme (TwentyTen):

<?php
/**
* The Template for displaying all single posts.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/

get_header(); ?>

<div id="container">
<div id="content" role="main">

<?php
// if user is not logged in
if ( !is_user_logged_in() ) {

// print a login form, that by default will redirect back to the current page
wp_login_form();

// if user is logged in, just go on as usual
} else {

/* Run the loop to output the post.
* If you want to overload this in a child theme then include a file
* called loop-single.php and that will be used instead.
*/
get_template_part( 'loop', 'single' );

}

?>

</div><!-- #content -->
</div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>


This is the file <em>single.php</em>. It may look somewhat different on other themes but the basics are the same and it could be easily adapted. See it in action on my testsite:
[[LINK href="http://test.druuf.com/wordpress/?p=1"]]http://test.druuf.com/wordpress/?p=1[[/LINK]]


Patrick MacAdams comments:

I just checked out the single.php file for my theme. It's pretty complicated. Are you available for hire to incorporate this for me?

Please contact me at
[email protected]


Ivaylo Draganov comments:

e-mail sent

2011-05-24

Jimish Gamit answers:

Install following plugin

http://wordpress.org/extend/plugins/theme-my-login/


Jimish Gamit comments:

This plugin themes the WordPress login, registration and forgot password pages according to your current theme. It replaces the wp-login.php file by using a page template from your theme. Also includes a widget for sidebar login.