[英]Wordpress - /wp-admin/ redirecting to /wp-login.php, when logged-in
[英]Redirecting non logged in users to home page in wordpress instead of /wp-admin or /wp-login or /wp-login.php
我正在WordPress網站的主題function.php文件中使用以下書面代碼來限制對wp-admin和wp-login頁面的訪問。 並且在訪問/ wp-admin和/ wp-login時工作非常好,並且如果用戶未登錄或不是管理員,它將重定向到我的網站url。 但是當我訪問https://ghardwar.com/wp-login.php時,它根本沒有重定向。 誰能建議我該怎么做。 也可以將已登錄的非管理員重定向到其他頁面,而不是同時保留該未登錄用戶重定向功能的主頁。
/**
* 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;
}
}
使用以下鏈接中的插件: https : //wordpress.org/plugins/remove-dashboard-access-for-non-admins/
我認為這可能對您有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.