Site admins want to put a lot of restrictions because a lot of content is very important in the website.
if the user is not logged in the website then the website admin restricts the user from viewing the content. If the user is not logged in, it is redirected to the login page or home page. So if the user is not logged in to the site then the user will not be able to read the user content.
We can set the non-login user redirection using the below code.
Add the below code in your (child) theme’s functions.php because if you will add the below code in the main theme’s functions.php file then when you will update the main theme that time your custom code will remove automatically.
If you don’t have a child theme then you can create your own plugin and then you can add all the custom code on this plugin.
ALSO READ: HOW TO CREATE CUSTOM PLUGIN.
add_action( 'admin_init', 'vivek_non_logged_in_user_redirection' );
function vivek_non_logged_in_user_redirection() {
if ( !is_user_logged_in() ) {
wp_redirect( 'http://vivekasodariya.blogspot.com/' );
exit;
}
}