admin管理员组文章数量:1290420
I make a web page in Wordpress using a certain theme. Now, this theme has an expected markup for the menus:
<ul id=”primary-navigation-main”>
<li>
<a href=””>Page 1</a>
</li>
<li>
<a href=””>Page 2</a>
</li>
<li>
<a href=””>Page 3</a>
</li>
</ul>
On the mobile menu the wishes are slightly different. In the company they want some transition while pressing on the menu item. Something that I solved at another (hardcoded) menu like that:
<ul id=”primary-navigation-main”>
<li>
<div class=”transition-div”></div>
<a href=””>
<p>Page 1</p>
</a>
</li>
<li>
<div class=”transition-div”></div>
<a href=””>
<p>Page 2</p>
</a>
</li>
<li>
<div class=”transition-div”></div>
<a href=””>
<p>Page 3</p>
</a>
</li>
</ul>
or like in this jsfiddle.
I don’t know if this is the best solution for this transition but it works.
So, I would like to add <div>
into <li>
before <a>
and in the <a>
I would like to add <p>
. I was fiddling with wp_nav_menu
and wp_nav_menu_items
but I wasn’t successful. Do I need to register <ul>
or something else? Also it seems I will have to use a Walker class but I don't know how.
Could anybody help me or simply tell me it's not possible?
I make a web page in Wordpress using a certain theme. Now, this theme has an expected markup for the menus:
<ul id=”primary-navigation-main”>
<li>
<a href=”https://example/page1”>Page 1</a>
</li>
<li>
<a href=”https://example/page1”>Page 2</a>
</li>
<li>
<a href=”https://example/page1”>Page 3</a>
</li>
</ul>
On the mobile menu the wishes are slightly different. In the company they want some transition while pressing on the menu item. Something that I solved at another (hardcoded) menu like that:
<ul id=”primary-navigation-main”>
<li>
<div class=”transition-div”></div>
<a href=”https://example/page1”>
<p>Page 1</p>
</a>
</li>
<li>
<div class=”transition-div”></div>
<a href=”https://example/page1”>
<p>Page 2</p>
</a>
</li>
<li>
<div class=”transition-div”></div>
<a href=”https://example/page1”>
<p>Page 3</p>
</a>
</li>
</ul>
or like in this jsfiddle.
I don’t know if this is the best solution for this transition but it works.
So, I would like to add <div>
into <li>
before <a>
and in the <a>
I would like to add <p>
. I was fiddling with wp_nav_menu
and wp_nav_menu_items
but I wasn’t successful. Do I need to register <ul>
or something else? Also it seems I will have to use a Walker class but I don't know how.
Could anybody help me or simply tell me it's not possible?
Share Improve this question asked Jun 16, 2021 at 13:05 Igor BeuermannIgor Beuermann 12 bronze badges1 Answer
Reset to default 0I overslept and came to a completely different solution with the same visual outcome. It simply doesn't use additional div
in the li
elements and p
elements in the a
element. The jsfiddle shows the solution thanks to the Keith J. Grant's idea I encountered. So instead of Wordpress I honed a bit my CSS skills.
But actually, the question remains: how to insert an arbitrary markup into a certain existing menu (in my case the primary menu of the chosen theme). That is into each menu item li
and then into each link a
, preserving the menu's URLs.
本文标签: insert div into a menu item before the link and more
版权声明:本文标题:insert div into a menu item before the link and more 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741498160a2381927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论