# Keep Selected Roles Out of the Divi Visual Builder

> Sends users without the capability you choose back to the normal page when they try to open the Divi Visual Builder, and hides the "Enable Visual Builder" admin bar link from them.

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: divi, roles, permissions, editor
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/divi-builder-access-by-role/

## Code

```php
// Capability needed to use the Visual Builder.
$wpide_divi_builder_capability = 'manage_options';

add_action( 'template_redirect', function () use ( $wpide_divi_builder_capability ) {
    if ( empty( $_GET['et_fb'] ) || ! is_user_logged_in() || current_user_can( $wpide_divi_builder_capability ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
        return;
    }

    wp_safe_redirect( remove_query_arg( array( 'et_fb', 'PageSpeed' ) ) );
    exit;
} );

add_action( 'admin_bar_menu', function ( $wp_admin_bar ) use ( $wpide_divi_builder_capability ) {
    if ( ! current_user_can( $wpide_divi_builder_capability ) ) {
        $wp_admin_bar->remove_node( 'et-use-visual-builder' );
    }
}, 999 );
```

## Notes

Divi's Role Editor gives finer control; this is a quick way to lock layouts for everyone below the chosen capability.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Keep Selected Roles Out of the Divi Visual Builder" 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/
