Type: php
Custom Role Redirect
// 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…Continue reading
Restrict Role Access
// Restrict Role Access / Kiri Vadivelu / 2026 function restrict_role_access() { // Check if user is trying to access admin area if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) { $user = wp_get_current_user(); // Check for Subscriber or…Continue reading
Untitled Snippet
Disable All Search
// Disable All Search / Kiri Vadivelu / 2026 function disable_search_query( $query, $error = true ) { if ( is_search() && !is_admin() ) { $query->is_search = false; $query->query_vars[‘s’] = false; $query->query[‘s’] = false; if ( $error ) { $query->is_404 =…Continue reading
No Index Category
// No Index Category / Kiri Vadivelu / 2026 add_filter(‘wp_robots’, ‘no_index_category’); function no_index_category(array $robots) { // Check if the current post has ‘members’ category if (is_single() && has_category(‘members’)) { $robots[‘noindex’] = true; } return $robots; }Continue reading
No Index Page
// No Index Page / Kiri Vadivelu / 2026 add_filter( ‘wp_robots’, ‘no_index_page’ ); function no_index_page( $robots ) { if ( is_page() ) { $robots[‘noindex’] = true; } return $robots; }Continue reading
Advanced Logout Redirect
// Advanced Logout Redirect / Kiri Vadivelu / 2026 add_action(‘wp_logout’, ‘redirect_after_logout’); function redirect_after_logout() { wp_safe_redirect(home_url()); exit; }Continue reading
Advanced Login Redirect
// Advanced Login Redirect / Kiri Vadivelu / 2026 function advanced_login_redirect( $redirect_to, $request, $user ) { if ( isset( $user->roles ) && is_array( $user->roles ) ) { // Role based user redirect if ( in_array( ‘member’, $user->roles ) ) {…Continue reading
Auto Admin Logout
// Auto Admin Logout / Kiri Vadivelu / 2026 add_filter( ‘auth_cookie_expiration’, ‘short_session_admin’, 10, 3 ); function short_session_admin( $expiration, $user_id, $remember ) { // Only apply the short timeout for administrators if ( user_can( $user_id, ‘manage_options’ ) ) { return 3600;…Continue reading