It doesn’t work. I have inserted it in root directory .htaccess. But it shows in the page “please login to continue” and in address bar it shows like this “https://mydomain.com/redirect_to=http%3A%2F%2Fmydomain.com%2Fwp-admin%2F&reauth=1”. I am not getting what I expected. Is there any code to redirect users who are not logged in to 404 page if they try to access wp-admin. I did for logged in users except administrator with this code
add_action(‘admin_init’, ‘no_mo_dashboard’);
function no_mo_dashboard() {
global $wp_query;
if (!current_user_can(‘manage_options’) && $_SERVER[‘DOING_AJAX’] != ‘/wp-admin/admin-ajax.php’) {
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 ); exit();
}
}
which redirects all users except administrator.