Timber 库不支持 "nav_menu_link_attributes" 过滤器?
Timber library doesn't support "nav_menu_link_attributes" filter?
我正在尝试使用 nav_menu_link_attributes 将其他内容附加到单个菜单项的 "href"。在我看来,Timber 库不支持此过滤器?
我的代码在 twentytwenty 上按预期工作,但是当我将主题切换到 Gesso-WP, that depends on Timber library. Also I cannot find any other filter than "nav_menu_css_class" inside the MenuItem
class https://github.com/timber/timber/blob/master/lib/MenuItem.php
时更改属性不会生效
function filter_menu_item_href( $atts ) {
if ( strpos( $atts['href'], 'site/SPageNavigator/my_account.html' ) !== false ) {
$atts['href'] .= '?NEXTURL=' . home_url();
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'filter_menu_item_href' );
Timber 上有哪些过滤选项可以更改此单个属性值?
我终于用 "wp_nav_menu_objects". This filter is present in the Menu
class from the Timber library plugin: https://github.com/timber/timber/blob/master/lib/Menu.php
解决了这个问题
function filter_menu_item_href( $menu ) {
foreach ( $menu as $item ) {
if ( strpos( $item->url, 'site/SPageNavigator/my_account.html' ) !== false ) {
$item->url .= '?NEXTURL=' . home_url();
}
}
return $menu;
}
add_filter( 'wp_nav_menu_objects', 'filter_menu_item_href' );
我正在尝试使用 nav_menu_link_attributes 将其他内容附加到单个菜单项的 "href"。在我看来,Timber 库不支持此过滤器?
我的代码在 twentytwenty 上按预期工作,但是当我将主题切换到 Gesso-WP, that depends on Timber library. Also I cannot find any other filter than "nav_menu_css_class" inside the MenuItem
class https://github.com/timber/timber/blob/master/lib/MenuItem.php
function filter_menu_item_href( $atts ) {
if ( strpos( $atts['href'], 'site/SPageNavigator/my_account.html' ) !== false ) {
$atts['href'] .= '?NEXTURL=' . home_url();
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'filter_menu_item_href' );
Timber 上有哪些过滤选项可以更改此单个属性值?
我终于用 "wp_nav_menu_objects". This filter is present in the Menu
class from the Timber library plugin: https://github.com/timber/timber/blob/master/lib/Menu.php
function filter_menu_item_href( $menu ) {
foreach ( $menu as $item ) {
if ( strpos( $item->url, 'site/SPageNavigator/my_account.html' ) !== false ) {
$item->url .= '?NEXTURL=' . home_url();
}
}
return $menu;
}
add_filter( 'wp_nav_menu_objects', 'filter_menu_item_href' );