Skip to content

Instantly share code, notes, and snippets.

@bjorn2404
Last active May 31, 2024 08:05
Show Gist options
  • Save bjorn2404/8afe35383a29d2dd1135ae0a39dc018c to your computer and use it in GitHub Desktop.
Save bjorn2404/8afe35383a29d2dd1135ae0a39dc018c to your computer and use it in GitHub Desktop.
WordPress allow iFrames with wp_kses_post filter
<?php
/**
* Add iFrame to allowed wp_kses_post tags
*
* @param array $tags Allowed tags, attributes, and/or entities.
* @param string $context Context to judge allowed tags by. Allowed values are 'post'.
*
* @return array
*/
function custom_wpkses_post_tags( $tags, $context ) {
if ( 'post' === $context ) {
$tags['iframe'] = array(
'src' => true,
'height' => true,
'width' => true,
'frameborder' => true,
'allowfullscreen' => true,
);
}
return $tags;
}
add_filter( 'wp_kses_allowed_html', 'custom_wpkses_post_tags', 10, 2 );
@praghavaji
Copy link

Super helpful. Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment