PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 7, 2022

[FIXED] Getting the "Open link in a new tab" property from a WordPress menu item

 February 07, 2022     timber, wordpress     No comments   

Issue

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

Solution

The below works in Timber v1.19.1 Twig 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 %}


Answered By - harceo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing