WordPress Theme: What is the right way to put inline CSS loading from a CSS file

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,

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744889956a4599348.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信