I am working inside the WP Admin area and there is a textarea that is using the default WP Editor, not TinyMCE. The WP Editor is removing the <style>
tag and also other HTML tags. I am calling it WP Editor, but maybe it's official know as something different? It's the editor with the two tabs in the right corner (Visual,Text)
Is there a way to prevent this Editor from removing all HTML tags?
The content I am adding in the WP Editor is being used in outgoing emails so it's really a full HTML document which is why I am trying to preserve the formatting and html tags.
I notice when I switch from the "Text" tab to the "Visual" tab many HTML tags are stripped.
I am working inside the WP Admin area and there is a textarea that is using the default WP Editor, not TinyMCE. The WP Editor is removing the <style>
tag and also other HTML tags. I am calling it WP Editor, but maybe it's official know as something different? It's the editor with the two tabs in the right corner (Visual,Text)
Is there a way to prevent this Editor from removing all HTML tags?
The content I am adding in the WP Editor is being used in outgoing emails so it's really a full HTML document which is why I am trying to preserve the formatting and html tags.
I notice when I switch from the "Text" tab to the "Visual" tab many HTML tags are stripped.
WordPress has a user capability called unfiltered_html
. Any user with the unfiltered_html
capability can post any HTML they want, including <script>
tags.
Due to security concerns, the unfiltered_html
capability is—by default—only granted to Administrators (in WordPress Multisite, it's only granted to Super Administrators).
If you need to add the unfiltered_html
capability to a non-(Super-)Admin user, you can use WP_User::add_cap()
to add it to a user:
add_action( 'admin_init', 'wpse_393657_grant_user_unfiltered_html' );
function wpse_393657_grant_user_unfiltered_html() {
$user = get_user_by( 'login', 'my_username' );
if ( ! user_can( $user, 'unfiltered_html' ) ) {
$user->add_cap( 'unfiltered_html', true );
}
}
...or WP_Role::add_cap()
to add it to a Role (eg, Editor).
add_action( 'admin_init', 'wpse_393657_grant_role_unfiltered_html' );
function wpse_393657_grant_role_unfiltered_html() {
$role = get_role( 'editor' );
if ( ! $role->has_cap( 'unfiltered_html' ) ) {
$role->add_cap( 'unfiltered_html', true );
}
}
(These code snippets are untested, and are meant to provide a starting point for you.)
Note that the capability assignments are permanent (ie, written to the database), and that the user or role will retain the unfiltered_html
capability until/unless you revoke it.