# Restrict Unfiltered HTML to Administrators

> Only administrators may save raw HTML such as scripts and iframes in posts. Editors get the same safe HTML filtering as authors.

- Type: PHP
- Runs: Run everywhere
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: security, html, roles, editors
- Author: WPIDE Team
- Installs: 6
- Updated: 2026-10-28
- Page: https://wpide.com/library/restrict-unfiltered-html/

## Code

```php
add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id ) {
    if ( 'unfiltered_html' === $cap && ! user_can( $user_id, 'manage_options' ) ) {
        return array( 'do_not_allow' );
    }

    return $caps;
}, 10, 3 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Restrict Unfiltered HTML to Administrators" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
