• Hello, I want everyone in my website to be public except the inside of posts, I’m using the post image and after it the more tag so that the title of post and post image appear in the categories page as excerpt, but I want when someone click this post title it tell them they should be logged in or register account.

    can this be achieved through a simple kind of code, I don’t know much about php, but a rule like: if in single-post must be logged on user.
    It’s like the private posts feature but the difference I want it open to all members not admins only, is there a way or a simple plugin for that?

Viewing 4 replies - 1 through 4 (of 4 total)
  • This plugin looks like it does just that (never used it, so I can’t be sure):

    https://www.ads-software.com/extend/plugins/wp-members/

    Thread Starter Walid

    (@walid3)

    well, actually I want more simple way or a plugin, like a code, I read somehwere about this code:

    <?php if (is_user_logged_in() ) { //only logged in user can see this ?>
    <div><p>the hidden text</p></div>
    <?php } ?>

    wonder if this can be used somehow in the single post template?

    Yes, can do it that way if you want. Exactly where and what to place in the if-statement depends on what theme you’re using. single.php is probably where you want it.

    <?php if ( is_user_logged_in() ) {
        /* The part of the template that you want hidden goes here */
    } else {
        echo '<p>Please <a href="' . wp_login_url( get_permalink() ) . '" title="Log in">log in</a> to see this post.</p>';
    }

    The content of your posts is displayed with the_content(), so just make sure that part is within the if-statement. Also, it’s always a good idea to use a child theme when editing your theme:

    https://codex.www.ads-software.com/Child_Themes

    Thread Starter Walid

    (@walid3)

    Great! that’s exactly what I was looking for, and I put the register link in the same line too, thanks so much ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to make single-post pages viewed only by members?’ is closed to new replies.