skip to Main Content

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 }}

2

Answers


  1. 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 %}
    
    Login or Signup to reply.
  2. 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"' }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search