Even if you don’t set “No” to “Redirect Customers to Account Dashboard After Logging In” in Magento 2 Stores > Configuration > Customers > Customer Configuration > Login Options, this code will work without any issue.
Implementing the code for this is pretty easy. You just have to add following code in your phtml file where you want to add custom login link or button.
<?php
$url = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
$login_url = $block->getUrl('customer/account/login', array('referer' => base64_encode($url));
<button type="button" onclick="location.href=' <?php echo $login_url; ?> '" title="<?php echo "Please Login" ?>" ><span><?php echo "Please Login" ?></span></button>
?>
Implementing the code for this is pretty easy. You just have to add following code in your phtml file where you want to add custom login link or button.
<?php
$url = $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
$login_url = $block->getUrl('customer/account/login', array('referer' => base64_encode($url));
<button type="button" onclick="location.href=' <?php echo $login_url; ?> '" title="<?php echo "Please Login" ?>" ><span><?php echo "Please Login" ?></span></button>
?>
Comments
Post a Comment