Skip to content

Instantly share code, notes, and snippets.

@adamsilverstein
Last active April 3, 2024 18:15
Show Gist options
  • Save adamsilverstein/10783774 to your computer and use it in GitHub Desktop.
Save adamsilverstein/10783774 to your computer and use it in GitHub Desktop.
WordPress expanded allowed tags for wp_kses with iframe, forms, etc.
function expanded_alowed_tags() {
$my_allowed = wp_kses_allowed_html( 'post' );
// iframe
$my_allowed['iframe'] = array(
'src' => array(),
'height' => array(),
'width' => array(),
'frameborder' => array(),
'allowfullscreen' => array(),
);
// form fields - input
$my_allowed['input'] = array(
'class' => array(),
'id' => array(),
'name' => array(),
'value' => array(),
'type' => array(),
);
// select
$my_allowed['select'] = array(
'class' => array(),
'id' => array(),
'name' => array(),
'value' => array(),
'type' => array(),
);
// select options
$my_allowed['option'] = array(
'selected' => array(),
);
// style
$my_allowed['style'] = array(
'types' => array(),
);
return $my_allowed;
}
@ckanitz
Copy link

ckanitz commented Apr 6, 2017

just want to leave a "thank you" for this :)

@adamsilverstein
Copy link
Author

Glad you found it useful @ckanitz!

@Ninetheme
Copy link

awesome!

@genetech-ahmed
Copy link

genetech-ahmed commented Apr 11, 2018

Thanks. Saved my day! 👍

@azamatx
Copy link

azamatx commented Feb 9, 2022

thank you!

@tuongpgjz
Copy link

May thank you!

@yashnaie
Copy link

hi
can you help me adding 'script' tag with 'src' attribute to allowedtag using function.php ?

@ikender
Copy link

ikender commented Apr 3, 2024

hi can you help me adding 'script' tag with 'src' attribute to allowedtag using function.php ?

Try this

    // script
    $my_allowed['script'] = array(
        'src' => array(),
    );

@ikender
Copy link

ikender commented Apr 3, 2024

Thanks @adamsilverstein - great tool, much appreciated

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