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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?