'What is the shortcode to pull the account page urls through without the anchor tags?
I am building a theme and require the links to the log in / log out / register pages but don't want the classic shortcode. I simply want the URL nothing else.
How are these urls called without the anchor tags?
Classic shortcode:
{% if shop.customer_accounts_enabled %}
{% if customer %}
<a href="/account">My Account</a>
{{ 'Log Out' | customer_logout_link }}
{% else %}
{{ 'Log In ' | customer_login_link }}
{{ 'Register' | customer_register_link }}
{% endif %}
{% endif %}
Required format:
{{ customer_logout_link_url }}
{{ customer_login_link_url }}
{{ customer_register_link_url }}
Solution 1:[1]
As far as I know, this isn't possible. The docs don't offer a way to do it.
Depending on why you want to do this, though, there is an alternative. This answer shows how you can add custom classes to the generated link, if that's what you need to do. A simpler version of it looks like:
{{ "Log Me Out!" | customer_logout_link | replace: '<a', '<a class="button button--primary"' }}
Solution 2:[2]
You can capture whatever is echoed as a link, then use that variable instead:
{% capture customer_logout_link_url %}{{ 'Log Out' | customer_logout_link }}{% endcapture %}
{% capture customer_login_link_url %}{{ 'Log In ' | customer_login_link }}{% endcapture %}
{% capture customer_register_link_url %}{{ 'Register' | customer_register_link }}{% endcapture %}
{% if shop.customer_accounts_enabled %}
{% if customer %}
<a href="/account">My Account</a>
{{ customer_logout_link_url }}
{% else %}
{{ customer_login_link_url }}
{{ customer_register_link_url }}
{% endif %}
{% endif %}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Brendan |
Solution 2 | Lukasz Formela |