Join our new community forum for support & discussion
Join NowHome › Support › Themes › ListingHive › Redirect if not user not logged in
Redirect if not user not logged in
-
AuthorPosts
-
Iva 11 months ago
Hello,
I’m using this code snippet for a call button:
📞
I would like that if user who is not logged in click the button it redirects him to log in page (like it does when they want to send a message). I believe it has to be done with user_login_modal but I’m not that much into coding. Could you please help me with that? Thanks.Iva 11 months ago<a class="button button--primary hp-button--wide" href="tel:%value%" target="_blank" rel="nofollow">📞</a>
Sorry, this codeIf you add this code snippet as part of template changes with some HivePress hooks then you need to add condition
if ( is_user_logged_in(){...
to check if user is logged in. If user is logged in then you show current code. If user is not logged in then you show this code snippet<a class="button button--primary hp-button--wide" href="#user_login_modal" target="_blank" rel="nofollow">📞</a>
Iva 11 months agoThank you for your answer!
It works fine – when user is not logged in and clicks to call the log in page appears. But when the user is logged in and clicks to call it just refreshes the page.If you make conditions in this way
if ( is_user_logged_in(){ // Your custom code here which you have post above }else{ // Code to open log in form }
then if user is logged in user should see this code
<a class="button button--primary hp-button--wide" href="tel:%value%" target="_blank" rel="nofollow">📞</a>
and if user is not logged in user should see this code
<a class="button button--primary hp-button--wide" href="#user_login_modal" target="_blank" rel="nofollow">📞</a>
Iva 11 months agoI also tried that way but in that case two buttons and some code appear – one that calls and one that opens log in page. Maybe I’m not inserting the code in the right place?
hivepress/templates/listing/view/block/listing-attributes-primary.php
Thank you for your help!Please try
hivepress/v1/templates/listing_view_block
hook to make changes in listing block.
Also please check this tutorial how to customise templates https://youtu.be/LkojYp-8uwYPlease do not make changes in core files
Iva 10 months, 4 weeks agoI watched the tutorial and read in the forum but still unable to figure it out.
However, thanks for your replies.Please try to put this code snippet in
hivepress/templates/listing/view/block/listing-attributes-primary.php
with child theme<?php if ( is_user_logged_in() ) : ?> <a class="button button--primary hp-button--wide" href="tel:%value%" target="_blank" rel="nofollow">📞</a> <?php else : ?> <a class="button button--primary hp-button--wide" href="#user_login_modal" target="_blank" rel="nofollow">📞</a> <?php endif; ?>
Iva 10 months, 4 weeks agoThat’s it. Thank you!
-
AuthorPosts
New Reply
This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.