如何在wordpress中为动态菜单添加跨度
I have a dynamic menu in wordpress using wp_nav_menu
, however I would like to add a span to just one of the list items.
I will demonstrate this in static HTML to show you what I would like to achieve.
I currently have this...
<li><a href="#">Test</a></li>
...but would like to achieve this...
<li><a href="#">Test<span>(icon)</span></a></li>
Is there anyway to do this dynamically?
Thanks in advance
我使用 我将在静态HTML中演示这个,以向您展示我想要实现的目标。 p>
我目前 有这个...... p>
...但是想要达到这个目的...... p>
无论如何动态地执行此操作? p >
提前致谢 p>
div> wp_nav_menu code>在wordpress中有一个动态菜单,但是我想添加一个 只有一个列表项。 p>
&lt; li&gt;&lt; a href =“#”&gt;测试&lt; / a&gt;&lt; / li&gt;
code>
&lt; li&gt;&lt; a href =“#”&gt; 测试&lt; span&gt;(icon)&lt; / span&gt;&lt; / a&gt;&lt; / li&gt;
code> pre>
Am I understanding the example correctly that you want an image icon inside the span? If so you could just use the wordpress generated class/ID for that specific li or anchor tag and give it a right aligned background image with CSS. You may have to also set it to have a wider width to accommodate the image. You wouldn't even need to add a span tag.
Here's the modified answer to give you want you want since my previous answer wasn't quite what you're looking for:
<script type="text/javascript">
jQuery('#menu-item-175 a').append('<span></span>')
</script>
Just change the #menu-item-175 to the correct ID of the li that surrounds the anchor you want to append to.