Title: auth_redirect help
Last modified: August 31, 2016

---

# auth_redirect help

 *  [ali-kazem](https://wordpress.org/support/users/ali-kazem/)
 * (@ali-kazem)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/auth_redirect-help/)
 * Hi,
 * I am working on making an auth_redirect around a button on my site, but I simply
   can’t figure out where to insert the auth_redirect for it to work.
 * The function has to be so that when the user clicks on the button, it will first
   check to see if the user is logged in, and if not, will take the user to a customized
   login page, then taking the user back to the page he/she was on before.
 * At the moment, with the code I’ve written, the button will take the user to a
   login page (and the user has to reload the page manually after registering), 
   then to the front page, but not back to the previous page.
 *     ```
       function custom_listify_single_job_listing_actions_after() {
   
       global $post;
       if ( is_user_logged_in() ) {
   
       $url = get_post_meta( $post->ID, 'my_meta_key', true );
   
       ?>
   
         <a href="<?php echo esc_url( $url );?>" class="button" target="_blank">BUTTON </a>
   
       <?php
   
       } else { 
   
           echo '<a href="http://mysite.com/login-to-see-the-link/" class="button">BUTTON</a>';
       };
       }
       add_filter( 'listify_single_job_listing_actions_after', 'custom_listify_single_job_listing_actions_after' );
       ```
   
 * I really hope you guys can help, as I’m struggling with this annoying error.
 * Thanks!

The topic ‘auth_redirect help’ is closed to new replies.

## Tags

 * [auth](https://wordpress.org/support/topic-tag/auth/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [else](https://wordpress.org/support/topic-tag/else/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [login](https://wordpress.org/support/topic-tag/login/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)
 * [user](https://wordpress.org/support/topic-tag/user/)

 * 0 replies
 * 1 participant
 * Last reply from: [ali-kazem](https://wordpress.org/support/users/ali-kazem/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/auth_redirect-help/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
