Astra主题如何禁止向三方产品分类菜单列表中插入ast-icon icon-arrow图标
遇到问题:Astra+Elementor开发网站时,在设计产品左侧菜单列表时,无论换哪个三方elementor widget插件中的菜单组件,菜单子项总是会被自动插入箭头图标,导致布局出现异常。

解决方案:
在function.php中关闭astra主题自动插入图标功能
/**
* 方案一:通过拦截菜单输出,正则移除 icon-arrow 标签
*/
add_filter( 'walker_nav_menu_start_el', function( $item_output, $item, $depth, $args ) {
// 只有在 Astra 主题环境下才执行
if ( strpos( $item_output, 'icon-arrow' ) !== false ) {
// 匹配包含 ast-icon icon-arrow 的 span 及其内部的 SVG 并将其替换为空
$item_output = preg_replace( '/<span class="ast-icon icon-arrow">.*?<\/span>/s', '', $item_output );
}
return $item_output;
}, 10, 4 );
最终效果如下:
