Skip to content

Instantly share code, notes, and snippets.

@bjorn2404
Last active April 22, 2024 15:08
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 );
@9ineNin9
Copy link

Thanks!!!!!!!!!!

@wildeones
Copy link

wildeones commented Sep 25, 2022

Hello,

Can I use this code to allow iframe in Woocommerce product category descriptions?

Can it be added to Code Snippets?

Thanks,

Jerome

@iRajatDas
Copy link

iRajatDas commented Dec 3, 2022

Hi, Is it possible to add custom html attribute to the Gutenberg Editor's column/row block?
I want to add the itemprop, itemtype and itemscope attribute to the div element.

@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