Wednesday 28 December 2016

Any defined user role redirect to homepage after login in Wordpress

Paste this function into your themes "functions.php" to redirect every specific user role from the admin back to your homepage:

add_action('admin_init', function() {
   
    $wp_user = wp_get_current_user();
   
    if(isset($wp_user->caps['subscriber']) && $wp_user->caps['subscriber']){
        wp_redirect(get_site_url());
        exit;
    }
   
});


Here, "subscriber" is user role slug change this as your user role.
it can be author, contributor, editor,

Ankit Shah PHP Expert

IT New Code suggest a solution for your problem related to coding, Specially .PHP, Wordpress, WooCommerce, Magento, HTML and CSS. Visit Our website for Information.

0 comments:

Post a Comment

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah