0

How can I make all the css in the twentyseventeen theme appear inline? I already tried putting the following in header.php:

<style>
    <?php include("/wp-content/themes/twentyseventeen/style.css");?>
</style>

and it did not work.

7
  • try simply 'style.css', as both are in the same folder
    – inarilo
    Aug 16, 2017 at 4:50
  • I created a child theme of it, but I still use style.css from twenty seventeen. Aug 16, 2017 at 12:05
  • 1
    why do you want it inline? this talks about the correct way to enqueue parent and child themes developer.wordpress.org/themes/advanced-topics/child-themes. alternatively try '../twentyseventeen/style.css'since both folders are under the same themes folder
    – inarilo
    Aug 17, 2017 at 11:37
  • Inline is supposed to be faster. Aug 17, 2017 at 15:49
  • Inlining "critical css" is faster, but probably not the entire stylesheet in the header. I'd recommend just putting the header/nav and critical css elements in there and take them out of the child css. I do hope you're working on a child of the theme and not the theme itself? If not, your changes will get removed every time you update. Aug 20, 2017 at 10:54

3 Answers 3

1

For some reason, taking out the beginning / solved my issue:

<style>
    <?php include("wp-content/themes/twentyseventeen/style.css");?>
</style>

After doing this, I removed it because I realized how much slower it made the page load.

1
  • this might actually work, but you should never include with relative paths. Sep 8, 2017 at 15:59
0

If you want to make it inline:

    <style>
        <?php $css_file = file_get_contents( 'http://yoursite.com/wp-content/themes/twentyseventeen/style.css' );
        echo '<style type="text/css">' . $css_file . '</style>';
    </style>
-1

Use wp_register_style()

// Include stylesheets
function stylename() {
    wp_register_style( 'stylename', '/wp-content/themes/twentyseventeen/style.css' );
    wp_enqueue_style( 'stylename' );
}
add_action( 'wp_enqueue_scripts', 'stylename' );
1
  • 5
    hmmm that is not inline Aug 16, 2017 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.