dongxing7083 2018-08-17 07:51
浏览 46
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • doulai8128 2018-08-17 08:24
    关注

    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 ';
    
        }
    
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?