• petroglyphic

    (@petroglyphic)


    I have read that if your theme includes both style.css and style.min.css, WordPress will automatically load style.min.css and fall back to style.css if the minified version is missing. I am enqueuing secondary css files using enqueue_scripts and want it to work the same way – load minified file if present and non-minified file as fallback – but can’t figure out how to do it. If I enqueue “style2.css” and “style2.min.css” is present in the same location “style2.css” is still loaded.

    If there is a more appropriate forum somebody please let me know!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    The files in question would be get_stylesheet_directory().’/style2.css’ or ‘/style2.min.css’, so you can use that to test their existence and based on the result of that, decide which to enqueue line you would any other CSS file.

    See https://codex.ww.wp.xz.cn/Function_Reference/get_stylesheet_directory

    Thread Starter petroglyphic

    (@petroglyphic)

    Thanks for the response.

    I know which files are there. What I am trying to figure out is: is there a way to enqueue so that the .min.css version of the stylesheet is called if it exists in the specified location but automatically fall back to the plain .css version if there is no minified version there.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    no, it’s up to you to code that if that’s what you want.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Enqueue minified css files’ is closed to new replies.