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

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler