WordPress.org

Forums

[resolved] need a simple function. redirect (7 posts)

  1. yortem
    Member
    Posted 1 year ago #

    hey, i want to focre visitors to log-in when a post is display.
    i think its something like

    if single {
    <?php auth_redirect(); ?>
    }

    something like that.
    how can i make it?

  2. Barry Hughes
    Member
    Posted 1 year ago #

    There are a few ways you might put this together, but you could take a look at these functions in the first instance:

  3. yortem
    Member
    Posted 1 year ago #

    i dont know php. can you make this little function for me?

  4. oxfordian3
    Member
    Posted 1 year ago #

    If you will not be coding at all, your best bet is to use a Membership plugin. There are several very good ones.

    For example, try the WP-Members plugin. Once installed you can specify that certain pages/posts of your site can be viewed only by a logged-in member.

  5. yortem
    Member
    Posted 1 year ago #

    how can i choose all posts from an array?
    this code worked but i need al ids.

    http://www.wpbeginner.com/wp-tutorials/force-users-to-login-before-reading-posts-in-wordpress/

    i dont want plugin

  6. Barry Hughes
    Member
    Posted 1 year ago #

    If that code works, why not use it - what is it you are struggling with?

  7. yortem
    Member
    Posted 1 year ago #

    it just for little id's and i need al posts.
    nvm i got it.

    function my_force_login() {
    global $post;
    
    if (!is_user_logged_in()) {
    auth_redirect();
    }
    }

    and put

    <?php my_force_login(); ?>

    before header in single.php

Topic Closed

This topic has been closed to new replies.

About this Topic