Metafield Link - Open in New Tab

I am using a metafield (Type: Link) on my product pages and the external link only opens up in the same tab. I have reached out to Shopify to ask for a solution to open in a new tab, but they have no answer. Does anyone have any recommendations?

1 Like

HI @wlh133

Can you define the attribute ‘target=’_blank’?

{%- if product.metafields.custom.test_link.value != blank -%}

{{product.metafields.custom.test_link.value.text}}
{%- endif -%}
1 Like

Hi Kyle, thanks for the reply. Where would this code be placed? All I am doing is entering the fields for Text Anchor and Link.

1 Like

Hi @wlh133

You will need to edit the code that was added to display your metafield link so that it opens in a new tab. If you don’t mind, please share your store link and collab request code so I can send request access your theme and check.

1 Like

Hi Dan, here is the link. I am using the Be Yours custom theme.

1 Like

Hi @wlh133

You can add this code to theme.liquid file before and check if it works


1 Like

Hi Dan. I added the code and it did not work. Below is the entire code for theme.liquid with your code included. Let me know if it should be placed elsewhere.

{%- assign text_direction = 'localization.text_direction_trigger' | t | downcase -%}

  
    
    
    
    
    
    

    {%- if settings.favicon != blank -%}
      
    {%- endif -%}

    {%- unless settings.type_header_font.system? and settings.type_body_font.system? -%}
      
    {%- endunless -%}

    

    {%- if page_description -%}
      
    {%- endif -%}

    {% render 'meta-tags' %}

    
    
    
    

    {{ content_for_header }}

    {%- liquid
      render 'css-variables'
      echo 'base.css' | asset_url | stylesheet_tag: preload: true
      
      if text_direction == 'rtl'
        echo 'rtl.css' | asset_url | stylesheet_tag
      endif
    -%}

    

    {%- unless settings.type_body_font.system? -%}
      
    {%- endunless -%}
    {%- unless settings.type_header_font.system? -%}
      
    {%- endunless -%}
    
    {%- if settings.predictive_search_enabled -%}
      
    {%- endif -%}
    {%- if settings.quick_view_enabled -%}
      
    {%- endif -%}
    {%- if settings.color_swatches_enabled -%}
      
    {%- endif -%}
    {%- if linklists.gift-wrapping.links != blank and linklists.gift-wrapping.links.first.type == 'product_link' -%}
      
      
    {%- endif -%}

    {%- render 'js-variables' -%}
  
    
    
  

  
  
   0 %} data-button-round{% endif -%}
  >
    
      {{ "accessibility.skip_to_text" | t }}
    

    {% render 'transition-cover' %}

    

      {% sections 'header-group' %}

      

        

        {% sections 'footer-group' %}
      

    

    {% sections 'overlay-group' %}

    
      - {{ 'accessibility.refresh_page' | t }}
    

    

    {%- if settings.image_loading_bar_enabled %}
      
    {% endif -%}
    {%- if settings.predictive_search_enabled -%}
      
    {%- endif -%}
    {%- if settings.quick_view_enabled -%}
      
    {%- endif -%}
    {%- if settings.color_swatches_enabled -%}
      
    {%- endif -%}
    {%- if linklists.gift-wrapping.links != blank and linklists.gift-wrapping.links.first.type == 'product_link' -%}
      
    {%- endif -%}
  

1 Like

Please update the code and add it here.


1 Like

Thank you Dan – this works!

1 Like

Happy I could help.

1 Like