WordPress.org

Support

Support » Plugins and Hacks » [Plugin: W3 Total Cache] Manual CSS/JS Placement

[Plugin: W3 Total Cache] Manual CSS/JS Placement

  • Can you tell W3 Total Cache where to place CSS/JS files by manually specifying a tag of some sort in the applicable PHP file? For instance, with W3 Minify you simply write <!-- WP-Minify CSS --> and <!-- WP-Minifiy JS -->. This is a must have!

    Currently, it is automatically placing them right after the <head> tag which breaks everything because my hosted CSS/JS files rely on external CSS/JS files, meaning my hosted files must be loaded after the external files, not before.

Viewing 5 replies - 1 through 5 (of 5 total)
  • wpreader

    @wpreader

    I’m in a similar situation and i’m looking for a solution as described above.

    Driklyn

    @driklyn

    Hi,

    I solved this by manually editing the source of the W3 Total Cache plugin. I now have my CSS files being placed directly before the </head> tag and my JS files being placed directly before the </body> tag.

    Been meaning to write a blog post about it and your reply inspired me to finally do so today. Here it is: W3 Total Cache: Better CSS/JS placement.

    wpreader

    @wpreader

    I’m still in search of something like this :

    HTML Tags to Change the Location of Minified JS and CSS by WP-Minify WordPress Plugin

    But i did find in the FAQs the following:

    You’ll need to manually update your theme to include your CSS and JS minify groups. The calls you’ll want to make for the various cases are:

    <?php if (function_exists(‘w3tc_styles’)): w3tc_styles(‘include’); endif; ?>
    Inserts the <head> CSS group at the location you choose. Multiple occurrences are allowed.
    <?php if (function_exists(‘w3tc_scripts’)): w3tc_scripts(‘include’); endif; ?>
    Inserts the <head> blocking JS group at the location you choose.
    <?php if (function_exists(‘w3tc_scripts’)): w3tc_scripts(‘include-nb’); endif; ?>
    Inserts the <head> non-blocking JS groups at the location you choose.
    <?php if (function_exists(‘w3tc_scripts’)): w3tc_scripts(‘include-body’); endif; ?>
    Inserts the <body> blocking JS group at the location you choose.
    <?php if (function_exists(‘w3tc_scripts’)): w3tc_scripts(‘include-body-nb’); endif; ?>
    Inserts the <body> non-blocking JS groups at the location you choose.
    <?php if (function_exists(‘w3tc_scripts’)): w3tc_scripts(‘include-footer’); endif; ?>
    Inserts the footer JS group at the location you choose.
    <?php if (function_exists(‘w3tc_scripts’)): w3tc_scripts(‘include-footer-nb’); endif; ?>
    Inserts the footer non-blocking JS group at the location you choose.

    However, i could not get it to work – . maybe because i’m always calling wp_head(). I should try it without calling wp_head().

    I’m hesitant to use your method as the changes would be over written when i update W3TC.

    Nice site by the way 🙂

    Driklyn

    @driklyn

    Interesting, I did not know those functions existed. If you can get those to work, then I’d definitely do it that way. Let me know if you do! 🙂

    Honestly, I never thought about the changes being overwritten when updating. I wonder if WordPress only updates files that have newer modified dates than the current files or if they do a full overwrite of all files. If they do the former, as long as the “w3-total-cache/lib/W3/Plugin/Minify.php” file wasn’t changed by W3 EDGE, you’d be safe. Of course, if it does get overwritten, it shouldn’t be too hard to redo the changes. Just be sure to save a link to my blog post somewhere in case this ever does happen.

    If you do manage to get those functions working, however, that’d be the best way.

    You can use a child theme to avoid having your changes lost when upgrading.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: W3 Total Cache] Manual CSS/JS Placement’ is closed to new replies.
Skip to toolbar