0

I am using Wordpress/Woocommerce for my website along with jekyll (static html generator). I want to change a button based upon user logged in or logged out.

\\ if user is logged in
<button>Log Out</button>
\\ else
<button>Log in</button>
1
  • 2
    You need PHP to know whether a user is logged in or not. So no. At the very least you'd need to make an AJAX request, as long as the sites are on the same domain. Jun 22 at 12:34
0

You can do this.

<?php if (is_user_logged_in()) : // user is logged in ?>
<button>Log Out</button>
<?php else : // user is not logged in ?>
<button>Log in</button>
<?php endif; ?>
0

Not sure about jekyll, but it is totally possible (though not recommended) in normal setup if the theme you are using calling the classes in body element using body_class() (almost all themes do). WordPress adds a classname logged-in in body if the user is logged in. Check for that and you are good to go.

Here is the jquery code to help you get started.

if ( $('body').hasClass('logged-in') ) {
    //Do your magic for logged in users
} else {
    //Do your magic for non logged in users
}  

This can be done using native JavaScript too, just google for a solution to check for classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.