Home / Admin / Custom Role Redirect
Duplicate Snippet

Embed Snippet on Your Site

Custom Role Redirect

Restrict access to dashboard for user with custom role.

Code Preview
php
<?php
// Custom Role Redirect / Kiri Vadivelu / 2026
function custom_role_dashboard() {
    // Replace 'contractor' with your actual custom role slug
    $restricted_role = 'contractor';
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
        $current_user = wp_get_current_user();
        
        // Check if user has the restricted role
        if ( in_array( $restricted_role, (array) $current_user->roles ) ) {
            wp_redirect( home_url() );
            exit;
        }
    }
}
add_action( 'init', 'custom_role_dashboard' );   

Comments

Add a Comment