• Resolved JJ

    (@jdagan)


    How can I set the condition so that only logged in users and in certain role will see the element?

    Thanks

    JJ

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter JJ

    (@jdagan)

    This is how I solved it:
    I added the following function to functions.php:

    /*adding custom values to Elementor Ele conditions*/
    add_filter( ‘eleconditions_vars’, ‘myuser_loggedin’);
    function myuser_loggedin ( $custom_vars ) {
    $custom_vars=is_user_logged_in();
    }

    I set the condition to:
    myuser_loggedin==true

    szwp

    (@szwordpress)

    Here how I solved the issue. I installed another plugin called Shortcode Variables by YeKen. This plugin provides out of the box several pre-defined variables. I leveraged the pre-defined user-id variable and set the condition accordingly.

    Here’s the condition – which in my case, if NO users are logged in, show the elementor section:

    [shortcode-variables slug=”sc-user-id”]==’ ‘;

    For your case, since you want to show the section only if users are actually logging in, the condition will look like this:

    [shortcode-variables slug=”sc-user-id”]!=’ ‘;

    Thread Starter JJ

    (@jdagan)

    @szwp Great idea. I like it. Thanks.

    Hello! Can you guys please help me? i wanted to do something similar like you. I wanted to show a specific content to the certain user. I tried it like szwp showed with:
    “[shortcode-variables slug=”sc-user-id”]==user_name” but for some reason it always shows false in the debug mode. ([shortcode-variables slug=”sc-user-id”]!=”” is workin if the user is logged in btw.) Do you have any idea how i could solve this?

    szwp

    (@szwordpress)

    The pre-defined variables defined in the Shortcode Variables plugin by YeKen are:

    sc-username – Display the logged in username.
    sc-user-id – Display the current user’s ID
    sc-user-ip – Display the current user’s IP address.
    sc-user-email – Display the current user’s email address.
    sc-username – Display the current user’s username.
    sc-first-name – Display the current user’s first name.
    sc-last-name – Display the current user’s last name.
    sc-display-name – Display the current user’s display name.
    sc-user-agent – Display the current user’s user agent

    Since you are using the [shortcode-variables slug=”sc-user-id”] you must equate it (==) to the logged in user id (assigned by wordpress) not to the user_name. Also use ’ not ” ( eg [shortcode-variables slug=”sc-user-id”]==’1‘; )

    Hope this helps

    @jdagan
    I can’t get it to work. Do you have any idea?
    I want to show one widget when logged in and the other one when not logged in.
    But your code doesn’t work for me..
    Thanks in advance!

    szwp

    (@szwordpress)

    Elementor section 1 to be displayed if user logged in
    Elementor section 2 not to be displayed if user not logged in

    Place this condition code [shortcode-variables slug=”sc-user-id”]!=’ ‘; in the Elementor section 1 (Edit Section -> Style -> Condition -> Write your Condition)

    Place this condition code [shortcode-variables slug=”sc-user-id”]==’ ‘; in Elementor section 2 (Edit Section -> Style -> Condition -> Write your Condition)

    PS make sure you have a space character between ‘ ‘.

    • This reply was modified 5 years, 9 months ago by szwp.

    @szwordpress
    Thanks for your answer.
    It still doesn’t work for me. When I did my first post I meant the code provided by @jdagan doesn’t work for me.
    But now I tried it your way. I installed the plugin and then put your code into the conditions tab and it still shows the same wigdets on all devices – whether logged in or not.
    It seems to me that the plugin Ele Conditions does not work at all, why ever.

    I am having the same problem and would love to try your solution. I just don’t understand. Where is the condition field where you put int you code?

    Thanks so much,
    Kerstin

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show only to logged in users and roles’ is closed to new replies.