问题描述
我有一个 wordpress Bootstrap 网站。我为下拉菜单功能实现了 WP Bootstrap Navwalker,没有问题。我使用此处提供的代码示例按照说明进行操作:https://github.com/wp-bootstrap/wp-bootstrap-navwalker。一切正常。
但是,下拉图标在左侧!
我添加了几个不同的图标只是为了测试,但它总是显示在左侧。我把它改成向右箭头,因为它让我很烦。
wp_nav_menu(array(
'theme_location' => 'menu-1','container' => 'div','container_class' => 'navbar-collapse collapse','container_id' => 'navcol-1','menu_class' => 'nav navbar-nav ml-auto','depth' => 2,'echo' => true,'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback','walker' => new WP_Bootstrap_Navwalker()
));
?>
if ( ! file_exists( get_template_directory() . '/inc/class-wp-bootstrap-navwalker.PHP' ) ) {
// File does not exist... return an error.
return new WP_Error( 'class-wp-bootstrap-navwalker-missing',__( 'It appears the class-wp-bootstrap-navwalker.PHP file may be missing.','wp-bootstrap-navwalker' ) );
} else {
// File exists... require it.
require_once get_template_directory() . '/inc/class-wp-bootstrap-navwalker.PHP';
}
add_action( 'after_setup_theme','register_navwalker' );
有人遇到过这个问题,或者知道我做错了什么吗?
解决方法
看看自定义的walker看起来像这条线就是图标在第一个的原因:
$item_output .= isset( $args->link_before ) ? $args->link_before . $icon_html . $title . $args->link_after : '';
您可以将其更新为:
$item_output .= isset( $args->link_before ) ? $args->link_before . $title . $icon_html . $args->link_after : '';
但我真的认为这应该通过 css
处理以将图标放置在右侧。