admin管理员组文章数量:1405138
So, I have the main Wordpress Theme file, the style.css
, and I would like to add some inline CSS to the header.
For that, I have a separated CSS file, mainly for organisation and because is more easy to maintain.
I also use the wp_add_inline_style
to properly inline the CSS code after the main linked CSS code.
The problem is, because the inline code is in a separated CSS file, and I need to use some the PHP function file_get_contents
, and to my knowledge this is not advisable to Wordpress Themes. Or is it?
I search options around the web and StackExchange and found:
One was using wp_remote_get
, but I don't think this is the right function for this (may be I am wrong).
Other alternative, that I have read was using ob_start
, include
and ob_get_clean
, but this seems must worse than file_get_contents
.
Other alternative that I have read was using Filesystem_API, but this seems unnecessary and adds complexity to theme for just a simply thing.
I don't what to put the CSS code inside the function.php
or any other PHP file. And I would like to do this the Right Way as possible!
Heres the code:
wp_register_style(
'my-theme-style',
get_stylesheet_uri(),
array(),
'',
'screen'
);
wp_enqueue_style( 'my-theme-style' );
wp_add_inline_style(
'my-theme-style',
file_get_contents(get_template_directory_uri() . '/css/inline.css')
);
Thanks for any Help!
本文标签: WordPress Theme What is the right way to put inline CSS loading from a CSS file
版权声明:本文标题:WordPress Theme: What is the right way to put inline CSS loading from a CSS file 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744889956a2630716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论