Sorry, that file cannot be edited in WordPRESS
The message “Sorry, that file cannot be edited.” in WordPress usually appears when you’re trying to edit a file through the WordPress dashboard
- File Permissions: The file permissions may be set to restrict editing. If the file permissions are too strict, WordPress will not allow you to make changes.
- Security Plugins: Security plugins may block access to sensitive files to prevent unauthorized changes. Plugins like Wordfence or Sucuri often enforce such restrictions.
- Hosting Restrictions: Some hosting providers restrict file editing through the WordPress dashboard for security reasons. They may require you to use FTP or the file manager in your hosting control panel instead.
- Code in
wp-config.php
: There may be a line of code in yourwp-config.php
file that disables the theme editor in WordPress. Look for this line: [Code 1.0.1] - WordPress Multisite: If you’re running a multisite installation, the network administrator might have disabled file editing for network security.
- Code in
function.php
: There may be a line of code in yourfunction.php
file that disables the theme editor in WordPress. Look for this line: [Code 20.1]
//Code 1.0.1
define('DISALLOW_FILE_EDIT', true);
//Code 2.0.1
$file = wp_normalize_path( $file );
Solutions
- Check File Permissions:
- Use FTP or your hosting control panel to access your WordPress files.
- Ensure that the file has the correct permissions (usually 644 for files and 755 for directories).
- Disable Security Plugins:
- Temporarily deactivate any security plugins and try editing the file again. If this works, you may need to adjust the plugin settings.
- Modify
wp-config.php
:- Access your site via FTP or your hosting file manager.
- Open the
wp-config.php
file. - Look for the
DISALLOW_FILE_EDIT
constant and ensure it is set tofalse
or remove it altogether (Code 1.0.2).
- Contact Hosting Provider: If your host is blocking the file editing, reach out to their support team and ask them to enable it or provide an alternative method.
- Modify
function.php
:- Access your site via FTP or your hosting file manager.
- Open the
\wp-includes\functions.php
file. - Look for the function validate_file( … ) and comment out the normalize in this function (Code 2.0.2)..
- The function converts the backslash
\
in$file
to a forward slash/
, which causes it to fail the$allowed_files
check. See the example in Ref: 2.0.2
//Code 1.0.2
define('DISALLOW_FILE_EDIT', false);
//Code 2.0.2
// Normalize path for Windows servers
// $file = wp_normalize_path( $file );
Ref 2.0.2
For example:
- Original
$file
:C:\xampp\htdocs\wordpress/wp-content/themes/your-theme/style.css
- After applying
wp_normalize_path
:C:/xampp/htdocs/wordpress/wp-content/themes/your-theme/style.css
Meanwhile, $allowed_files = ['style.css']
still points to C:\xampp\htdocs\wordpress/wp-content/themes/your-theme/style.css
.