Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // While specified areas are under development, redirect users to home page if not logged in
- add_filter( 'wp', 'f040925b_redirect', 0 );
- function f040925b_redirect( $content ) {
- global $post;
- if(
- (
- $post->post_type == '[custom_post_type_name]'
- ||
- is_post_type_archive( '[custom_post_type_name]' )
- ||
- is_tax( '[custom_taxonomy_name]' )
- )
- &&
- !is_user_logged_in()
- ) {
- wp_redirect( get_home_url() );
- exit;
- }
- return $content;
- }
- /* Essentially, this runs three early checks:
- 1) Does the $post object's post type match what you're trying to hide?
- 2) Is this URL a post type archive for the post type you're trying to hide?
- 3) Is this URL a taxonomy/term page for the taxonomy you're trying to hide?
- If any of these is a match and the user is not logged in, then the user is redirected to homepage. */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement