Ad

Getting The "Open Link In A New Tab" Property From A WordPress Menu Item

- 1 answer

In a typical menu item loop is there something like item.target when setting the 'Open link in a new tab' option?

I see the issue has been brought up before and is now available in Timber V2 but is there a way to get it working in available in Timber version 1.0?

{% for item in menu.items %}
    <li>
        <a href="{{ item.link }}" target="{{ item.target }}">{{ item.title }}</a>
    </li>
{% endfor %}
Ad

Answer

The below works in Timber v1.19.1Twig v1.42.5

{% for item in menu.items %}
    <li>
        <a href="{{ item.link }}"
           target="{{ item.meta( '_menu_item_target' ) ? item.meta( '_menu_item_target' ) : '_self' }}">
              {{ item.title }}
        </a>
    </li>
{% endfor %}
Ad
source: stackoverflow.com
Ad