从 WordPress 菜单顶部删除 a href

发布于 2024-10-07 23:41:16 字数 696 浏览 0 评论 0原文

我想从 WordPress 菜单上的函数 wp_list_pages() 中删除自动 a href 链接,但我不想从子菜单中删除 href,只能从顶部菜单中删除

,例如:

<li><a href="www.games.co.il">Games-not remove thr href</a> 
  <ul>
    <li><a href="www.x4.co.il">Menu0-remove the auto href</li>
    <ul>
      <li><a href="www.x1.co.il">sub-menu 1-do not remove the auto href</a></li> 
        <ul>
          <li><a href="www.ddd.co.il">**not** remove the href</li> 
        </ul>
      <li><a href="www.x1.co.il">sub-menu 2 not-remove the auto href</li>
    </ul>
  </ul>    
</li>

i want to remove the automatic a href link from the function wp_list_pages() on wordpress menu, but i do not want to remove the href form the sub menu, only from the top menu

for example:

<li><a href="www.games.co.il">Games-not remove thr href</a> 
  <ul>
    <li><a href="www.x4.co.il">Menu0-remove the auto href</li>
    <ul>
      <li><a href="www.x1.co.il">sub-menu 1-do not remove the auto href</a></li> 
        <ul>
          <li><a href="www.ddd.co.il">**not** remove the href</li> 
        </ul>
      <li><a href="www.x1.co.il">sub-menu 2 not-remove the auto href</li>
    </ul>
  </ul>    
</li>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

总以为 2024-10-14 23:41:16

定位 LI 中主列表直接子级的链接。

$("ul#menu > li a").removeAttr("href");

http://api.jquery.com /child-selector/

或者保留 url 并返回 false。URL

$("ul#menu > li a").click(function(){ return false; });

仍会出现在浏览器中,但单击链接不会执行任何操作(如果启用了 JS)。

Target the links in LI's that are direct children of the main list..

$("ul#menu > li a").removeAttr("href");

http://api.jquery.com/child-selector/

Or leave the url in place and return false on them..

$("ul#menu > li a").click(function(){ return false; });

The URL would appear in the browser still, but clicking the link would do nothing(if JS is enabled).

红颜悴 2024-10-14 23:41:16

正如大卫·多沃德(David Dorward)所说:“别再想要那样了!”。

您可以做的是将主页重定向到第一个子项目(通常是概述等)。这最适合用于兼容性,以防有人禁用了 JS,并且下拉/悬停菜单仍然有效。

或者在主页内容上包含一个子菜单,这将帮助用户轻松导航到您想要的位置,而不会牺牲可用性。

As David Dorward stated "Stop wanting that!".

What you CAN do, is a redirect on your main pages to the first sub item (usually an overview, etc). This is best used for compatibility in case someone has JS disabled, and the dropdown/hover menu still works.

Alternatively include a sub menu on the main page contents which will help the user navigate where you want them to just as easily without sacrificing usability.

噩梦成真你也成魔 2024-10-14 23:41:16

使用 jQuery:
像这样的东西:

$("ul#menu li:first a").removeAttr("href");

Using jQuery:
Something like this:

$("ul#menu li:first a").removeAttr("href");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文