Pluginless maintenance mode w/ functions.php

I’m always looking for ways to ditch plugins to keep from bloating WordPress even more than I already do ;). I prefer working on a live server so I end up resorting to utilizing .htaccess to allow access to a specified IP addresses only. Using this snippet in functions.php is way easier since it just looks if a user can edit themes and if they’re logged in. Easy peasy!

Toss this into your functions.php file.

// Admin Access Only
function maintenance_mode() {
  if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
add_action('get_header', 'maintenance_mode');


Comments are closed.