Title: need a simple function. redirect
Last modified: August 21, 2016

---

# need a simple function. redirect

 *  Resolved [yortem](https://wordpress.org/support/users/yortem/)
 * (@yortem)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/)
 * 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?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Barry Hughes](https://wordpress.org/support/users/websitebakery/)
 * (@websitebakery)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557034)
 * There are a few ways you might put this together, but you could take a look at
   these functions in the first instance:
    - [is_user_logged_in()](http://codex.wordpress.org/Function_Reference/is_user_logged_in)
    - [wp_safe_redirect()](http://codex.wordpress.org/Function_Reference/wp_safe_redirect)
 *  Thread Starter [yortem](https://wordpress.org/support/users/yortem/)
 * (@yortem)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557037)
 * i dont know php. can you make this little function for me?
 *  [oxfordian3](https://wordpress.org/support/users/oxfordian3/)
 * (@oxfordian3)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557061)
 * 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.
 *  Thread Starter [yortem](https://wordpress.org/support/users/yortem/)
 * (@yortem)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557071)
 * 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/](http://www.wpbeginner.com/wp-tutorials/force-users-to-login-before-reading-posts-in-wordpress/)
 * i dont want plugin
 *  [Barry Hughes](https://wordpress.org/support/users/websitebakery/)
 * (@websitebakery)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557123)
 * If that code works, why not use it – what is it you are struggling with?
 *  Thread Starter [yortem](https://wordpress.org/support/users/yortem/)
 * (@yortem)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557126)
 * 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

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘need a simple function. redirect’ is closed to new replies.

## Tags

 * [auth_redirect](https://wordpress.org/support/topic-tag/auth_redirect/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [yortem](https://wordpress.org/support/users/yortem/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/need-a-simple-function-redirect/#post-4557126)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
