Link to an internal CSS using PHP (3 posts)

  1. Aymen
    Posted 2 years ago #

    Hello Helpers !

    I have a small problem here: I did a SEO test for my WordPress site with GTMETRIX and I got some errors that I wish to fix all to increase my SEO score and become more friendly with search engines (especially with Google).

    They told me to Inline my small css files like the subscriptions.css of the Jetpack plugin:

    So I did copy the code inside subscriptions.css and I pasted it between <style type="text/css"> and <style> tags in the head section (header.php), then I deleted the subscriptions.css file.

    The internal CSS code that I've added to header.php works fine.


    Ine the phph file of the Jetpack plugin, there is a line of PHP code that calls for the CSS file that I've deleted (subscriptions.css) like so:
    wp_register_style( 'jetpack-subscriptions', plugins_url( 'subscriptions/subscriptions.css', __FILE__ ) );

    I need to replace the subscriptions/subscriptions.css with a link to my <style type="text/css"> that I've added to header.php

    Tell me how please ... Thank You

  2. Dave Naylor
    Posted 2 years ago #

    Hopefully you're using a child theme because if not, any updates will overwrite your edited header file and you'll have to redo your work.

    You might be better off employing a plugin such as:


    I need to replace the subscriptions/subscriptions.css with a link to my <style type="text/css"> that I've added to header.php

    No you don't. Embedded (not inlined) CSS is already loaded in the page, so you don't need to link anything. Your plugin will still try and load its stylesheet though, so you may want to de-regsiter the style.


    I'm unsure how the page load time will be effected by the plugin registering its style then you de-registering later on.

  3. Aymen
    Posted 2 years ago #

    Thank you WPRANGER for taking time to answer !

    I'm not so good using PHP functions.
    The page load time get affected (according to Google Page Speed and GTMETRIX), but it's okay, I can get over that if it's not a very important part of speed optimization.

    Thank's for suggesting the plugin, but just in case that I've installed a lot of other usefull ( very usefull) plugins that I don't want to surcharge my site using another one. But If you do insist on installing it as I can really profite from, then I'm READY!

Topic Closed

This topic has been closed to new replies.

About this Topic