网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

使用nav_menu_item_id在Wordpress菜单中编辑特定元素

GG网络技术分享 2025-03-18 16:12 1


问题描述:

I want to add number of items in wishlist next to li element in my \"menu_main\". To problem is I can\'t how to edit that specific element. I tried sth like

add_filter( \'nav_menu_item_id\', \'filter_function_name_5519\', 10, 3 );

function filter_function_name_5519( $menu_id, $item, $args ){

// filter...

if (!is_admin() && $args->theme_location == \'menu_main\' &&

yith_wcwl_count_products() && $menu_id == \'menu-item-5519\') {

$item .= \'<li>\' . yith_wcwl_count_products() . \'</li>\';

}

return $item;

}

But that doesn\'t work. Important for me is to echo yith_wcwl_count_products() within li element, because I need to position it with css via position relative and absolute.

网友观点:

you can\'t change this way you are dealing with an object here so if you want to change the title you can do it this way:

 add_filter(\'nav_menu_item_id\', \'filter_function_name_5519\', 10, 3);

function filter_function_name_5519($menu_id, $item, $args)

{

if (!is_admin() && $menu_id == \'menu-item-42\') {

$item->title .= \' test \';

}

}

标签:

提交需求或反馈

Demand feedback