简体   繁体   English

将未登录的用户重定向到wordpress中的主页,而不是/ wp-admin或/ wp-login或/wp-login.php

[英]Redirecting non logged in users to home page in wordpress instead of /wp-admin or /wp-login or /wp-login.php

I am using below written code in my themes function.php file of WordPress site to restrict access to wp-admin and wp-login pages. 我正在WordPress网站的主题function.php文件中使用以下书面代码来限制对wp-admin和wp-login页面的访问。 and it's working very fine upon accessing /wp-admin and /wp-login and it's redirecting to my site url if user is not logged in or not administrator. 并且在访问/ wp-admin和/ wp-login时工作非常好,并且如果用户未登录或不是管理员,它将重定向到我的网站url。 but when i visit https://ghardwar.com/wp-login.php its not redirecting at all. 但是当我访问https://ghardwar.com/wp-login.php时,它根本没有重定向。 Can anyone suggest me that what should i do to achieve this. 谁能建议我该怎么做。 Also is it possible to redirect logged-in non admins to some other page instead of home page retaining that non logged in user redirect function simultaneously. 也可以将已登录的非管理员重定向到其他页面,而不是同时保留该未登录用户重定向功能的主页。

 /**
 * Disable admin bar on the frontend of your website
 * for subscribers.
 */
function wpestate_disable_admin_bar() { 
    if ( is_admin() && ! current_user_can( 'administrator' ) && 
       ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
        add_filter('show_admin_bar', '__return_false'); 
    }
}
add_action( 'after_setup_theme', 'wpestate_disable_admin_bar' );



/*
*   Restrict non logged users to certain pages
*/

add_action( 'init', 'blockusers_init' );

function blockusers_init() {
    if ( is_admin() && ! current_user_can( 'administrator' ) && 
       ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
        wp_redirect( home_url() );
        exit;
    }
}

Use the plugin from the following link : https://wordpress.org/plugins/remove-dashboard-access-for-non-admins/ 使用以下链接中的插件: https : //wordpress.org/plugins/remove-dashboard-access-for-non-admins/

I think this might help you. 我认为这可能对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM