How to allow iframes and script tags in WordPress KSES
8/17/2023
2 min read
What is WordPress KSES?
wp_kses is part of WordPress sanitizing data functions where it’s primary function is to filter text content and strips out disallowed HTML.
This function makes sure that only the allowed HTML element names, attribute names, attribute values, and HTML entities will occur in the given text string.
By default WordPress doesn’t allow iframe and script tags in the post content since this can be a potential security risk.
But in some scenarios where it is needed WordPress allows to enable this tags using the wp_kses_allowed_html filter.
How to allow iframes and script tags in the post content?
You can now also use wp_kses_post( $string ) to filter any other string in your theme.
In Block API version 2 or higher, blocks must use `useBlockProps` hook to properly insert the attributes and event handlers needed to enable block behaviour.