Black Friday Black FridayUp to 85% off all WP Ghost plans.48 months from $49, or pay once for lifetime. SHOP NOW

How to Disable File Editing in WordPress

One stolen login should not edit your code banner

Log in, then go to Appearance and open Theme File Editor. If a code editor opens, anyone who gets into an admin account can rewrite your theme’s PHP from the browser.

That’s the built-in file editor. It’s handy once, and it turns one stolen password into full control of your site.

What an attacker does with it

An admin login lets them open functions.php, paste a few lines and run their own code on your server. No upload, no plugin install, no alarm. The Plugin File Editor works the same way.

Many hacked sites start exactly like this. The password was the problem, and the editor made it worse.

Turn the editor off

Open wp-config.php in your site root. Add this line above the comment that says “That’s all, stop editing.”

define('DISALLOW_FILE_EDIT', true);

Save the file. The Theme File Editor and Plugin File Editor menu items disappear.

Also block plugin and theme installs

If you want to go further, add a second line.

define('DISALLOW_FILE_MODS', true);

This also blocks installing, updating and deleting plugins and themes from the dashboard. That includes core and plugin updates, so you take over updating by other means. I’d use the first line on every site and the second only where deployments run from a repository.

Lock down wp-config.php itself

The file now holds your security settings, so protect it. Set its permissions to 440 or 400 where the host allows it, using the steps in how to change file permissions in WordPress. Do the same for .htaccess, following the guide to setting it read-only.

Protect the account behind it

The editor was only dangerous because admin logins were weak. Turn on two-factor authentication for every administrator and limit login tries with brute force protection.

Check that it worked

Reload the dashboard. Appearance should no longer show Theme File Editor, and Plugins should no longer show Plugin File Editor. Visiting /wp-admin/theme-editor.php directly should show a permission error.

The complete hack prevention guide lists the next hardening steps once this one is done.

FAQ

Will it break my site?

No. You only lose the editor in the dashboard. SFTP still works.

What does DISALLOW_FILE_MODS add?

It blocks installs, updates and deletions from the dashboard too.

Can an attacker switch it back off?

Only by editing wp-config.php another way, so lock that file down.

Do I need a plugin?

No. It’s one line in wp-config.php.