• Join the Best Wordpress and Elementor Support forum

    Provide or get advice on everything Elementor and Wordpress, ask questions, gain confirmation or just become apart of a friendly, like minded community who love Wordpress and Elementor


    Join us!

Show and Hide Elements based on user role

MJS

MJS

New Member
Hi All, I have a question that may be obvious however I am unsure on how to achieve it. Is there a way to show and hide elements, like a button or links, in elementor based on user roles? For example have a button show up if the user is not logged into the system but then be invisible if the user is logged in.
 
sms-design

sms-design

Member
There is various solutions and loads of plugins > what type of site are you building.

You also have the WP user role manager


 
sms-design

sms-design

Member
Here's a fair review of plugins and there are lots


If you are looking for a almost free solution with a good community forum "S2 Member"
 
Community

Community

Administrator
Staff member
The way I've done it is a bit of a mixture of plugin and custom functions, Although I havent got time to help you with your function, maybe you can do what you require with this example (Which is actually more complex than you would need as integrates a few different aspects for us.

So I would use : https://wordpress.org/plugins/ele-conditions/

I would then enter something like

Code:
$haveCourses === true

In the conditional part of the section ( which the above plugin produces )

Code:
function new_keywords( $custom_vars ) {   
    $custom_vars['haveCourses'] = false;

    $current_user_id = get_current_user_id();
    $member = new MeprUser($current_user_id);
    $active_memberships = $member->active_product_subscriptions();
    if (!empty($active_memberships)){
        foreach ($active_memberships as $key => $value) {
            $post_type = get_field('associated_post_type', $value);
            if ($post_type != NULL && $post_type != 'NULL' && $post_type != 'post') {
                $post_types[] = get_field('associated_post_type', $value);
            }
            
        }
    }

    global $post;

    
    $fields =get_fields($post->ID);


    if ($fields) {
        foreach($fields as $key=>$val)
        {   
            if ($val == '') {
                $custom_vars['acf_' . $key] = false;
            } else {
                $custom_vars['acf_' . $key] = true;
            }
            
        }
    }



    if (!empty($post_types)) {
        $custom_vars['haveCourses'] = true;
    }

    // Check if

    $custom_vars['test'] = $post->ID;

    return $custom_vars;


}
 

Latest Resources

Other Elementor Resources

elementor official

Still stuck? Ask the forum

Post your question with a screenshot and a link if you can, and a member will usually reply within a day. Free to join, no sales pitch.

Create a free account
Top