Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Last active January 10, 2024 10:19
Show Gist options
  • Save mehul0810/180632d0fa15a7b1ab122ac07d2aae77 to your computer and use it in GitHub Desktop.
Save mehul0810/180632d0fa15a7b1ab122ac07d2aae77 to your computer and use it in GitHub Desktop.
Allow Script Tags to be added in content for specific user roles. Works will multisite as well.
<?php
/**
* Allow Script Tags to be used in editor for Administrator user role.
*
* @author Mehul Gohil <hello@mehulgohil.com>
*/
function allow_unfiltered_html_for_administrators( $allowed_tags ) {
// Bailout, if the logged-in user role is not `administrator`.
if ( ! current_user_can( 'administrator' ) ) {
return $allowed_tags;
}
$allowed_tags['script'] = array(
'src' => true,
'height' => true,
'width' => true,
'charset' => true,
'async' => true
);
return $allowed_tags;
}
add_filter( 'wp_kses_allowed_html', 'allow_unfiltered_html_for_administrators' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment