douxingti9307 2016-03-02 17:39
浏览 98
已采纳

如何在子主题中将<span>添加到wp_nav_menu

I can manage this in the wordpress files but it will be overwritten in the next update. How can i code this in the child theme functions or can i overwrite the wp_nav_menu.php file in the child theme?

/**
     * Filter a menu item's title.
     *
     * @since 4.4.0
     *
     * @param string $title The menu item's title.
     * @param object $item  The current menu item.
     * @param array  $args  An array of {@see wp_nav_menu()} arguments.
     * @param int    $depth Depth of menu item. Used for padding.
     */
    $title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );

    $item_output = $args->before;
    $item_output .= '<a'. $attributes .'><span>';    //NOTE THE SPAN IS ADDED HERE
    $item_output .= $args->link_before . $title . $args->link_after;
    $item_output .= '</span></a>';        //AND HERE
    $item_output .= $args->after;

Thank you in advance!

  • 写回答

1条回答 默认 最新

  • dongzhao1865 2016-03-02 17:51
    关注

    you can run an argument straight in to wp_nav_menu without using a walker

    <?php wp_nav_menu( array('link_before' => '<span>', 'link_after' => '</span>')); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料