【问题标题】:Add Wordpress menu css classes to <span class="">将 Wordpress 菜单 css 类添加到 <span class="">
【发布时间】:2018-01-27 20:58:51
【问题描述】:

想添加添加到Wordpress菜单中的CSS类如下图

到我的菜单

      wp_nav_menu( array( 
        'theme_location'    => 'header', 
        'container'         => false, 
        'items_wrap'        => '%3$s', 
        'after'             => '<span class="icon-thumbnail"><i class="fa "></i></span>'
      )); 

创建

<li>
  <a href="/">Dashboard</a> 
  <span class="icon-thumbnail">
  <i class="fa fa-reorder"></i>
  </span>
</li>

因此,将添加到 Wordpress Admin 中的 menu_item 的 CSS 类添加到我的菜单中的 &lt;i class="fa "&gt;&lt;/i&gt; 中。因此,看起来像&lt;i class="fa fa-reorder"&gt;&lt;/i&gt;

【问题讨论】:

  • 解释更多没有发生什么?你到底想要什么?

标签: php css wordpress wordpress-theming


【解决方案1】:

这样做

wp_nav_menu( array( 
     'theme_location'    => 'header', 
     'container'         => false,
     'items_wrap'        => '%3$s',
));

在 wp admin 中的 css 输入框中放这个类

fa fa-reorder

这应该可以解决您需要添加附加 fa 类以添加 fontawesone 图标的问题。

编辑: 这是引导程序的walker。

https://github.com/wp-bootstrap/wp-bootstrap-navwalker

根据需要编辑代码

walker 中的这一部分将被编辑以解决您的问题。

if ( ! empty( $item->attr_title ) ) {
  $pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' );

  if ( false !== $pos ) {
      $item_output .= '<a' . $attributes . '><span class="glyphicon ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></span>&nbsp;';
  } else {
      $item_output .= '<a' . $attributes . '><i class="fa ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></i>&nbsp;';
  }
} else {
    $item_output .= '<a' . $attributes . '>';
}

这应该可以解决问题

【讨论】:

  • 谢谢。但是,我需要将该类添加到'',因此它在'' ">'。因此,无论是使用 css 输入 'fa fa-reorder' 还是 'fa-reorder' 我仍然没有达到我需要的结果。
  • 你需要为此创建一个walker。你在使用引导程序吗?
  • @Darren Mathers 有效果吗?如果是,请将其标记为已解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-26
  • 2014-01-12
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多