skip to Main Content

WordPress Code Snippets


Restricting Access to the wp-admin Area

Limit access to the wp-admin area to specific IP addresses to improve security and reduce unauthorized access.

function codebykp_restrict_wp_admin_access() {
    if (!current_user_can('administrator') && !in_array($_SERVER['REMOTE_ADDR'], array('YOUR_IP_ADDRESS'))) {
        wp_die('You are not allowed to access this page.');
    }
}
add_action('admin_init', 'codebykp_restrict_wp_admin_access');


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search