Gulp wp_style_add_data(“主题流样式”,“rtl”,“替换”)返回“主题.最小-rtl. css”而不是“主题-rtl.最小. css”

i7uq4tfw  于 2022-12-16  发布在  Gulp
关注(0)|答案(1)|浏览(460)

我正在使用understrap主题作为启动主题。和gulp编译的scss文件到css的'ltr'和'ltr',我有在我的css文件夹:

css
|____custom-editor-style-rtl.css
|____custom-editor-style-rtl.min.css
|____custom-editor-style-rtl.min.css.map
|____custom-editor-style.css
|____custom-editor-style.min.css
|____custom-editor-style.min.css.map
|____theme-rtl.css
|____theme-rtl.min.css
|____theme-rtl.min.css.map
|____theme.css
|____theme.min.css
|____theme.min.css.map

当我使用wp_style_add_data( 'understrap-styles', 'rtl', 'replace' );来获得rtlcss路径时,我得到以下内容:

<link rel="stylesheet" id="understrap-styles-rtl-css" href="http://192.168.1.12/wp/wp-content/themes/medialab/css/theme.min-rtl.css?ver=0.9.4.1619044994" media="all">

我得到的不是.../theme-rtl.min.css而是.../theme.min-rtl.css
我怎样才能得到:.../theme-rtl.min.css

<link rel="stylesheet" id="understrap-styles-rtl-css" href="http://192.168.1.12/wp/wp-content/themes/medialab/css/theme-rtl.min.css?ver=0.9.4.1619044994" media="all">
s5a0g9ez

s5a0g9ez1#

我只是通过将'replace'替换为rtl css get_template_directory_uri() . '/css/theme-rtl.min.css'的路径来修复它

wp_style_add_data( 'understrap-styles', 'rtl', get_template_directory_uri() . '/css/theme-rtl.min.css' );

编辑:我发现这种方法存在一些问题,我找到了更好的解决方案:

wp_enqueue_style( 'understrap-styles', get_template_directory_uri() . '/css/theme.min.css', array(), $css_version );
wp_style_add_data( 'understrap-styles', 'rtl', 'replace' );
wp_style_add_data('understrap-styles', 'suffix', '.min');

第一种方法是喜欢.../theme-rtl.min.css,但是它在html文档中保留了.../theme.min.css链接,这导致了!important css之间的一些冲突,所以我必须找到另一种解决方案。新的解决方案将.../theme.min.css替换为.../theme.min-rtl.css,然后最后一行代码修复了'.min'后缀,这样链接就变成了.../theme-rtl.min.css

相关问题