• I have been using script tags in custom HTML blocks in years, and they have worked flawlessly.

    Out of the blue, script tags are being stripped from custom HTML blocks, leaving the enclosed JavaScript exposed as text.

    Apart from a more or less recent update to 6.9.4 , I haven’t changed aynthing on the site.

    I have set define( ‘DISALLOW_UNFILTERED_HTML’, false ); in wp-config.php and cleared all caches, to no effect.

    Has there been a recent change to WordPress in what is being stripped from custom HTML blocks?

    How would I go about debugging this?

    Thanks, Florian

    • This topic was modified 6 months, 1 week ago by flberger. Reason: Typo fix
Viewing 3 replies - 1 through 3 (of 3 total)
  • Start by checking your user role, only Administrators have the unfiltered_html capablity by default.

    If this is a Multisite install, only Super Admins can save raw <script>tags in the editor unless the unfiltered_html capability was manually added to the Administrator role.

    Also check any security plugin settings related to XSS filtering or HTML sanitization.

    Otherwise, try deactivating all plugins, then reactivate them one by one and test each time until you find the cause.

    If that does not resolve the issue, switch temporarily to a default WordPress theme to rule out a theme-specific issue.

    The define('DISALLOW_UNFILTERED_HTML', false) line in wp-config isn’t doing anything. That constant only matters when it’s set to true. On single-site WP, admins already have unfiltered_html, so setting it false just confirms the default.

    What I’d do: open DevTools Network tab, drop a <script> tag into a Custom HTML block, save, and grab the PATCH to /wp-json/wp/v2/posts/{id}. Look at two things:

    – Request body content: what the editor sent – Response body content.raw: what the server kept after kses

    If the script is in the request and gone from the response, it’s wp_filter_post_kses chewing it up server-side. That usually means a plugin (Wordfence, Solid Security, an SEO suite with XSS rules) is hooked in and downgrading your capability. If it’s already missing from the request, the block editor itself stripped it on the way out, which usually means a Gutenberg-side security filter.

    That at least tells you whether to disable a server hook or look at the editor’s JS filters before you do the plugin bisect.

    Thread Starter flberger

    (@flberger)

    That sounds very helpful, @alexfv . Can’t try it right now, but I’ll check it out later. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘script tags suddently stripped from custom HTML blocks’ is closed to new replies.