Disable file editing in WordPress admin dashboard

WordPress ships with a built-in code editor under Appearance → Theme File Editor and Plugins → Plugin File Editor that lets administrators edit PHP, JavaScript, and CSS files directly from the browser. This feature was designed for the era when WordPress was primarily a blogging tool and hosting environments made FTP the standard file management method. In the modern WordPress ecosystem it represents one of the most significant attack vectors on an otherwise well-configured site. The reasoning is straightforward: if an attacker gains access to any administrator account — through a phishing email, a reused password exposed in a data breach, a brute-force login attack against the admin page, or a session hijacking vulnerability — the theme editor gives them an immediate path to remote code execution. A single line of PHP injected into functions.php via the editor runs on every page load with the full privileges of the web server user. They can create backdoor shell scripts, harvest user data from the database, redirect visitors to malware sites, or destroy the installation entirely, all from within an authenticated browser session that looks completely normal in server access logs. Disabling the editor removes this attack surface entirely without affecting site functionality in any way — legitimate developers use FTP, SFTP, SSH, or version-controlled deployments to modify theme and plugin files, never the browser editor. The fix is a single constant added to wp-config.php, which is the most appropriate location for security-critical configuration constants in WordPress. Setting DISALLOW_FILE_EDIT to true removes the editor menu items from both the Appearance and Plugins menus and returns a permission denied response to any direct request to the editor URL. This constant has been supported since WordPress 2.8 and is a standard recommendation in WordPress security hardening guides. For sites that also want to prevent plugin and theme installation from the admin panel — another privilege escalation vector — the related DISALLOW_FILE_MODS constant provides broader coverage and also disables the core auto-update system, so use it deliberately. The minimal, targeted approach is to set only DISALLOW_FILE_EDIT unless you have a specific reason to lock down file modifications more broadly. A complementary security measure is blocking direct HTTP access to wp-config.php via .htaccess.

Problem: The WordPress admin theme and plugin editors allow code injection if an admin account is ever compromised.

Solution: Add the following line to your wp-config.php file, above the /* That’s all, stop editing! */ comment:

<?php
// Disable the theme and plugin file editors in WordPress admin
define( 'DISALLOW_FILE_EDIT', true );

// Optional: also block plugin/theme installation and core auto-updates
// define( 'DISALLOW_FILE_MODS', true );

NOTE: After adding this constant, the Appearance → Theme File Editor and Plugins → Plugin File Editor menu items will disappear immediately for all admin users, including yourself. This is intentional — if you need to edit theme files, use an SFTP client or SSH access. DISALLOW_FILE_MODS is a stricter option that also prevents installing, updating, or deleting plugins and themes from the admin panel, and disables WordPress automatic background updates. Enable it only if your deployment process fully controls code changes through version control and does not rely on admin-panel updates.