• Skip to primary navigation
  • Skip to main content
  • Skip to footer

GDS Web Design

Not Just another WordPress Developer

  • Home
  • Portfolio
  • Services
  • Process
  • Blog
  • Contact
  • Go to All
  • Go to Getting Started
  • Go to Tutorials
  • Go to Design and Redesign
  • Go to Updating and Improving
  • Go to Marketing
  • Go to Coding
  • Go to Glossary
  • Go to Announcements
  • Go to Opinion

Redirect non-admin users from wp-admin

This simple function will redirect any logged in users (apart from admins) back to the homepage if they try to access the wp-admin folder directly. Add the following code your theme’s functions.php file.

add_action('admin_menu', 'redirect_dashboard');
function redirect_dashboard(){
    if( !current_user_can('administrator') ){
        if( preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) && ('index.php' != $menu[$page][2]) ) wp_redirect(get_bloginfo('url'));
    }
}

 

September 16, 2012 by Gary Filed Under: Coding Tagged With: Wordpress, Snippets

  • Go to NEXT
  • Go to ALL
  • Go to PREVIOUS

Signup to Email Post Alerts

And I'll let you know when I publish something new.
Loading

Footer

Recommended

  • FAQ
  • Testimonials
  • Contact

Trending

  • Website Upgrade for Decor Books
  • Contact Us
  • Web design for Chichester telephone business
  • Website Re-Design for Custom Marine Parts Business
  • Website design for Hog Roast business
  • Website Design for Garage Door Business

Recent Projects

Website Redesign for Trinsic

Website for Sportsboat World

Website Makeover for Hooves and Love

Website for Hampshire Cleaning Company

Website Upgrade for Decor Books

View more of my work

Copyright © 2011–2026 GDS Web Design · Legal Notice · Locations

Website by gds-code-icon [Converted] GDS Web Design