Prevent non-logged in users from viewing Project details in FreelanceEngine

Updated on November 14, 2024 in No Category
0 on February 9, 2015

This is a tutorial for FreelanceEngine. It helps you prevent non-logged in users viewing the project details.

We can use WordPress’s hook: template_redirect to do this.  Simply add the below code to your child theme functions.php.

add_action('template_redirect', 'prevent_nologin_user_access_project');
function prevent_nologin_user_access_project() {
 if(is_singular( 'project' ) && !is_user_logged_in() ) {
 wp_redirect( home_url() );
 }
}

The above code will redirect the users to the Home page. If you want redirect users to a specific page, you can change the link as below:

 wp_redirect( "your url" );

Also, you can easily prevent users entering other post type details page by changing “project ” to “your post type name”.

if(is_singular( 'the post type name' ) && !is_user_logged_in() ) {
 wp_redirect( home_url() );
 }
 
  • Liked by
Reply