Show Elementor Sections Only to Logged-In or Logged-Out Visitors
Hides any Elementor container, section or widget with the CSS class "wpide-logged-in" from guests, and anything with "wpide-logged-out" from members, without Elementor Pro.
Opens WPIDE on
Code
$wpide_el_login_visibility = function ( $should_render, $element ) {
if ( ! $should_render || ! is_object( $element ) || ! method_exists( $element, 'get_settings' ) ) {
return $should_render;
}
if ( class_exists( '\Elementor\Plugin' ) && \Elementor\Plugin::$instance->editor && \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
return $should_render;
}
$classes = ' ' . $element->get_settings( '_css_classes' ) . ' ' . $element->get_settings( 'css_classes' ) . ' ';
if ( false !== strpos( $classes, ' wpide-logged-in ' ) && ! is_user_logged_in() ) {
return false;
}
if ( false !== strpos( $classes, ' wpide-logged-out ' ) && is_user_logged_in() ) {
return false;
}
return $should_render;
};
foreach ( array( 'widget', 'section', 'column', 'container' ) as $wpide_el_type ) {
add_filter( "elementor/frontend/{$wpide_el_type}/should_render", $wpide_el_login_visibility, 10, 2 );
}
Notes
Add the class under Advanced > CSS Classes. Elements stay visible in the editor so you can still edit them.
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.