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条)