When using stylesheets I like to use wp_enqueue_style to have wp handle the loading. For some reason this works perfectly fine when I am logged in. But when I am not logged in the include statment gets wrapped in html comments, thus the browser doesn load the stylesheet.
When loading I use:
wp_enqueue_style("a-unique-name-style", plugins_url('/css/filename.css',path);
I also tried
function name_enqueue_style() {
error_log(__LINE__);
wp_enqueue_style("a-unique-name-style", plugins_url('/css/filename.css',path));
error_log(__LINE__);
}
add_action( 'wp_enqueue_scripts', 'name_enqueue_style' );
But name_enqueue_style does not load at all. (Nothing in the error log either.)
I run this from both the plugin “main” php as from functions that build widgets.
What is happening? I don’t even know where to start looking.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
as Tom J Nowell asked in the comments a caching plugin was the culprit. In this case WP Fastest cache. Just deleting the cache did not work. Turning the caching off and on again fixed the problem.
update: I did some more digging and the fact it gets commented is correct. The caching plugin also runs a code minimizer. For some reason the minimized code did not use the stylesheet I added. Turning it off and on again forced a rerun of the minimizer (I guess).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0