I posted this to the wordpress stack exchange, but I also think its a good idea to post this here
Hello I found a function that when placed in the functions.php, it injects the entire stylesheet into the head on the website:
add_action( 'wp_head', 'internal_css_print' );
function internal_css_print() {
echo '<style>';
include_once get_template_directory() . '/style.css';
echo '</style>';
}
It works great, the whole stylesheet goes in the head just fine, but one minor issue is that the urls in the css are broken. For example when the following is in the css file:
background: url('images/hero-desktop.jpg');
When the stylesheet is linked normally, this returns http://localhost:8888/wp-content/themes/my-theme/images/hero-desktop.jpg
-> works
But when the stylesheet is injected in the head it returns: http://localhost:8888/images/hero-desktop.jpg
--> doesnt work. The path is broken.
To fix this I can do a simple search and replace in the css to change url('
to url('/wp-content/themes/my-theme/
but there has to be a better way.
So I was thinking is there something to add to the function at the top, so before spitting out the whole css file into the head, it dynamically changes the url paths from url(/images/)
to /wp-content/themes/my-theme/images/
. If this is possible that would be great so its just a one time setup instead of searching and replacing css on an already developed site.
Thanks!