• Hello all!

    I’ve been searching for several days for a way to hide <?php the_content(); ?> in the single.php and to show it only to registered users [putting a paragraph like “to read you must register (link) or login (link)].

    Can anyone please help me finding a way to do this, please?

    Thanks and regards!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Something like:

    <?php
    	if ( is_user_logged_in() ) {
    		the_content();
    	}
    	else {
    		echo "You are not logged in.\n";
    }
    ?>

    Resources:
    https://www.google.com/search?q=wordpress+test+if+user+is+logged+in

    Thanks for the reply MichaelH!

    I can try that in single.php, right?

    And the only thing I need is to replace the <?php the_content(); ?> for the code above?

    Regards.

    Yes that code would go in your Loop in single.php.

    Thread Starter ricardodias

    (@ricardodias)

    Michael, it works perfectly, thanks!!!
    ??
    Can I ask you one more thing, please?
    How do I put the register and login links on the php… instead of your “You are not logged in.”?

    To be something like:
    “To view the content you must register (link on the word “register”) or login (link on the word “link”)
    ?

    Thanks!

    Thread Starter ricardodias

    (@ricardodias)

    GREAT, I got it!!!
    ??
    After some research and experiments I used this:

    <?php
    if ( is_user_logged_in() ) {
    the_content();
    }
    else {

    echo ‘You must <a href=”‘ . get_settings(‘siteurl’) .
    ‘/wp-register.php”>’ . __(‘REGISTER’) . ‘</br> or do the <a href=”‘ .
    get_settings(‘siteurl’) . ‘/wp-login.php”>’ . __(‘LOGIN’) . ‘.’;
    }
    ?>

    Thanks for the help!
    I promise that I will ask you some more things.
    :D:D:D
    Regards

    Thread Starter ricardodias

    (@ricardodias)

    Michael… here I am again… I warned you!
    ??

    Is it possible for the person who see the message “to register or to login” in the single.php, after clicking on the login and do it, be redirected to the same page he was before?

    Thanks!

    hi there is there anyone that can help me
    i want to make a scroll er
    so people can write a comment when they send it you see it in the
    scroll er with a candle next to it moving up the way 200×500

    thanks
    p.s its for a memorial site
    https://www.fallenangelsite.com

    Thread Starter ricardodias

    (@ricardodias)

    MichaelH, I took a look at the plugin but I couldn’t figure out how to do what I want.
    What I want is to know if it’s possible to the user that do the login be redirected to the single.php he was before doing the login.
    I want this because I have many new posts per day and as they are only viewable to registered users, they all have to do the login. If they are in a post and if they click on the login link they will have to go to the registration/login console and after doing it I wish they could turn back to the specific post they were before.
    Thanks!!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show <?php the_content(); ?> only to registered users… is it possible?’ is closed to new replies.