Hide Elementor Templates From Non-Administrators
Removes the Templates menu Elementor adds to wp-admin for everyone except administrators and blocks direct access to the list, protecting headers, footers and popups.
Opens WPIDE on
Code
// Capability required to manage templates.
$wpide_el_templates_capability = 'manage_options';
add_action( 'admin_menu', function () use ( $wpide_el_templates_capability ) {
if ( ! current_user_can( $wpide_el_templates_capability ) ) {
remove_menu_page( 'edit.php?post_type=elementor_library' );
}
}, 999 );
add_action( 'load-edit.php', function () use ( $wpide_el_templates_capability ) {
if ( isset( $_GET['post_type'] ) && 'elementor_library' === $_GET['post_type'] && ! current_user_can( $wpide_el_templates_capability ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
wp_die( esc_html__( 'Sorry, you are not allowed to access this page.' ), 403 );
}
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.