Security Guide Beginner 5 min

Lock Down wp-config.php: 7 Settings Every WordPress Site Should Have

Seven wp-config.php settings that close common holes in WordPress: no file editor in wp-admin, HTTPS for logins, no visible errors, fresh salts and more. Copy, paste, test.

Hardening WordPress · Part 1 of 4
TutorialBeginner15 minTested on WordPress 7.1Updated November 13, 2026

Most WordPress hacks don’t start with something clever. They start with a stolen admin password, an error message that gives away a file path, or a plugin left two years out of date. wp-config.php can’t fix weak passwords, but it can make each of those mistakes much less useful to an attacker.

This is part 1 of our Hardening WordPress series. Every setting below is a plain PHP constant: no plugin needed.

Before you start

  • Access to your site’s filesSFTP, SSH or your hosting file manager
  • A fresh backupIncluding a copy of wp-config.php itself
  • HTTPS working on the siteNeeded for setting 2
Where the lines go

Add everything above the line /* That's all, stop editing! Happy publishing. */. Anything below it runs after WordPress has started, and most of these settings will then do nothing.

The seven settings

  1. Turn off the theme and plugin file editor

    WordPress lets administrators edit theme and plugin PHP files from Appearance → Theme File Editor and Plugins → Plugin File Editor. If anyone ever gets into an admin account, that is a ready-made way to add malicious code. Turn it off:

    wp-config.phpPHP
    define( 'DISALLOW_FILE_EDIT', true );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    Both editor screens disappear. Updates and plugin installs still work. Our snippet library has more on this setting.

    Deploy with Git or Composer?

    Go one step further with define( 'DISALLOW_FILE_MODS', true );. It also blocks installing, updating and deleting plugins and themes from wp-admin, and stops automatic updates. Only use it when updates reach the site some other way.

  2. Always use HTTPS for logins and wp-admin

    wp-config.phpPHP
    define( 'FORCE_SSL_ADMIN', true );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    Logins and the admin area are then only ever served over HTTPS, so passwords and login cookies are never sent in plain text. If your site already redirects everything to HTTPS, this is a safety net for the day that redirect is misconfigured.

  3. Never show PHP errors to visitors

    Error messages can reveal file paths, plugin names and database details. On a live site they belong in a log, not on the page:

    wp-config.phpPHP
    define( 'WP_DEBUG', false );
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', '0' );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    WP_DEBUG_DISPLAY and the ini_set line also cover errors that happen before WordPress has fully loaded.

  4. Log errors privately when you need them

    When something breaks, you still want to see what happened. Turn debugging on with a log file outside the public web folder, so nobody can open it in a browser:

    wp-config.phpPHP
    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', '/home/youraccount/logs/wp-debug.log' );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    Use this instead of the lines in step 3, not as well. Replace the path with a folder your host gives you above public_html. The default log, wp-content/debug.log, sits in a public folder and can often be downloaded by anyone who guesses the address.

    Note

    Switch back to step 3 when you are done. A debug log that grows for months can fill your disk.

  5. Keep WordPress security releases automatic

    WordPress installs minor releases (7.1.1, 7.1.2…) on its own by default. These are the security fixes. Make sure nothing on the site has turned that off, and say so in your config:

    wp-config.phpPHP
    define( 'WP_AUTO_UPDATE_CORE', 'minor' );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    Use true instead if you also want major versions installed automatically. Search your wp-config.php and must-use plugins for AUTOMATIC_UPDATER_DISABLED too: if it is set to true, no automatic updates run at all.

  6. Stop scripts being saved in post content

    By default, administrators and editors can save any HTML in posts, including <script> tags. If one of those accounts is taken over, that is an easy way to put malware in front of every visitor:

    wp-config.phpPHP
    define( 'DISALLOW_UNFILTERED_HTML', true );
    Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

    WordPress then filters unsafe tags out of everyone’s content, administrators included.

    Check your embeds first

    Some embed codes, tracking snippets and forms are pasted into posts as raw HTML with scripts. After this change WordPress strips those scripts when the post is saved. Move them into your theme, a plugin or a block that loads them properly before turning this on.

  7. Refresh your secret keys and salts

    The eight AUTH_KEY, SECURE_AUTH_KEY… lines sign every login cookie. If they are still the placeholder text, were copied from another site, or might have leaked, replace them. With WP-CLI:

    TerminalBASH
    wp config shuffle-salts
    Success: Shuffled the salt keys.

    No WP-CLI? Open the WordPress.org salt generator, copy all eight lines and paste them over the existing ones.

    Note

    Everyone is logged out when the salts change, you included. That is the point: any stolen login cookie stops working too.

You should now see

Appearance and Plugins no longer show a file editor, /wp-admin/ always opens on https://, and a broken plugin shows a plain error page instead of a PHP message with file paths.

The site broke after editing wp-config.php3 common fixes
  • White screen or “There has been a critical error”. Usually a missing semicolon or quote. Restore your backup copy of wp-config.php and add the lines again one at a time.
  • Redirect loop on /wp-admin/ after FORCE_SSL_ADMIN. Your site sits behind a proxy or CDN that ends HTTPS before WordPress. Ask your host how they pass the HTTPS flag, or remove the line until they do.
  • An embed or form disappeared from a post. That is DISALLOW_UNFILTERED_HTML at work. See the warning in step 6.

Two more things worth doing

Move wp-config.php up one folder. WordPress looks for it one level above the WordPress folder if it isn’t next to wp-load.php. Above public_html, it can’t be served even if PHP ever stops working on the server. Not every host allows this, so check first.

Tighten its file permissions. wp-config.php only needs to be readable by the web server. 440 or 400 is a good target. Your host can tell you which works on their setup.

What doesn’t help much

Changing the database table prefix from wp_ is often listed as a security step. It doesn’t stop an attack that can already run SQL, and changing it on a live site is easy to get wrong. Spend the time on updates and strong logins instead.

The complete block

Here are the always-on settings together, ready to paste above the “stop editing” line:

wp-config.phpPHP
// Security settings.
define( 'DISALLOW_FILE_EDIT', true );
define( 'FORCE_SSL_ADMIN', true );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', '0' );
define( 'WP_AUTO_UPDATE_CORE', 'minor' );
define( 'DISALLOW_UNFILTERED_HTML', true );
Tested on WordPress 7.1 · PHP 8.3Checked November 13, 2026

Then refresh your salts. Next in this series: security headers, so the browser helps protect your visitors too.

Snippet

Add HTTP Security Headers via WordPress

Set X-Content-Type-Options, X-Frame-Options, Referrer-Policy, and Permissions-Policy response headers from WordPress to improve your site's security posture without touching server config.

PHPIntermediate
View

Was this helpful?

Written by Nahnu Plugins

We build and maintain WordPress plugins. Every guide is tested on a fresh WordPress site before it goes out, and checked again when WordPress updates.

More guides

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only