Created
October 23, 2023 13:48
-
-
Save dparker1005/04d617fc2bc079dbbee38617451f58b9 to your computer and use it in GitHub Desktop.
Redirect logged out users from a specific post to the site's login page.
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 | |
// Copy below this line. | |
/** | |
* Redirect logged out users from a specific post to the site's login page. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_redirect_logged_out_users_from_post() { | |
if ( is_single( 20206 ) && ! is_user_logged_in() ) { | |
wp_redirect( wp_login_url() ); | |
} | |
} | |
add_action( 'template_redirect', 'my_redirect_logged_out_users_from_post' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment