[英]Manipulate Wordpress Menu href attribute on custom template
I have a custom template in which i am calling wp_nav_menu
function like below. 我有一个自定义模板,我在其中调用wp_nav_menu
函数,如下所示。
<?php
$defaults = array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'nav',
'container_class' => 'main-nav',
'container_id' => '',
'menu_class' => 'nav',
'menu_id' => 'sub-nav',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => new Nav_Walker_Nav_Menu()
);
wp_nav_menu($defaults);
The output i am receiving is like 我收到的输出就像
<a href="#about" class="nav-link">About</a>
When hoveing over the link i get the following url: 当停留在链接上时,我得到以下URL:
http://localhost/mysite/cart/#about
I want to remove cart/
from this url so that i will get the url 我想从此网址中删除cart/
,以便获取网址
http://localhost/mysite/#about
In the dashboard, if you put #about
as the link destination, it will create the link like you have which will take you as an anchor link to #about
on any page it's displayed on (cart, whatever). 在仪表板中,如果将#about
作为链接目标,它将像您所创建的那样创建链接,该链接将把您作为指向#about
的锚定链接(显示在购物#about
的任何页面)。 If you want the link to be http://localhost/mysite/#about
, you need to enter that full url in the menu link in the dashboard. 如果您希望链接为http://localhost/mysite/#about
,则需要在仪表板的菜单链接中输入完整的URL。
Just remember to change it when you take the site live. 只要记得在上线站点时进行更改即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.