Last active
September 12, 2024 14:16
-
-
Save kimwhite/f495eb82d793de19c17ee5d9079dee79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 // do not copy this line. | |
/** | |
* This recipe will redirect non-members from your blog page if all of the post are protected and you have hidden from non-memberts. | |
* | |
* 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 mypmpro_redirect_away_if_blog_is_empty() { | |
global $wp_query; | |
global $wp; | |
//Is this the blog page? | |
if ( $wp_query->query_vars['pagename'] === 'blog' ) { | |
//Theres no posts in the blog right now so redirect away | |
if ( ! have_posts() ){ | |
wp_redirect( '/activate-membership/'); | |
die(); | |
} | |
} | |
} | |
add_action( 'template_redirect', 'mypmpro_redirect_away_if_blog_is_empty' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment