Last active
December 16, 2015 19:39
-
-
Save rfmeier/5486273 to your computer and use it in GitHub Desktop.
Redirect a to a specific page depending on whether the user is authenticated or not.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Callback for WordPress 'template_redirect' action. | |
* | |
* http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect | |
* | |
* @return none | |
*/ | |
function my_custom_redirect(){ | |
// if not on specific page, continue to page (use is_single() to detect a specific post) | |
if( ! is_page( 10 ) ) | |
return; | |
// if the user is logged in, continue to page | |
if( is_user_logged_in() ) | |
return; | |
// redirect to page id 5 | |
wp_redirect( get_permalink( 5 ) ); | |
// (optional) prevent other action callbacks from performing addtional redirects | |
exit(); | |
} | |
add_action( 'template_redirect', 'my_custom_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment