Security PHP Beginner

Stop Administrators Posting Unfiltered HTML

Filter scripts and other risky HTML from posts by every user, including administrators, to limit the damage of a stolen account.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
wp-config.php 1 lines
define( 'DISALLOW_UNFILTERED_HTML', true );

Where to add this

Recommended wp-config.php Above the line that says "That's all, stop editing!" in your wp-config.php file.

Administrators and editors can normally put any HTML in posts, including <script> tags. If one of those accounts is compromised, an attacker can add malicious scripts to your pages. This constant makes WordPress filter everyone’s content the way it filters authors’ content.

How it works

DISALLOW_UNFILTERED_HTML removes the unfiltered_html capability from all users. Content they save is then run through wp_kses_post(), which removes scripts, inline event handlers and other unsafe markup while keeping normal formatting, links, images and embeds.

Things to watch

  • Custom HTML blocks containing scripts, such as some embed codes or tracking pixels, will be stripped when saved. Add those through your theme, a code snippets plugin or your page builder’s code element instead.
  • Content saved before you add the constant isn’t changed until it’s edited again.

How to test it

As an administrator, add a Custom HTML block containing <script>alert(1)</script> and save. Reload the editor: the script tag should be gone.

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