admin管理员组

文章数量:1310169

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.

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.

Share Improve this question edited Dec 27, 2020 at 17:34 pietervanderstar asked Dec 27, 2020 at 17:18 pietervanderstarpietervanderstar 313 bronze badges 4
  • 1 Do you have any performance optimisation or caching plugins/features active? Also where/when does the code in your question executed ( the add_action call specifically )? – Tom J Nowell Commented Dec 27, 2020 at 18:07
  • Thanks a lot, apparently I had to turn the caching off and on again to get rid of the comment. Maybe not an answer that fits all the requirements, but if you post it as an answer I'll accept it as such. – pietervanderstar Commented Dec 27, 2020 at 20:23
  • Forgot to add that I did delete the cache, but that clearly wasn't enough. – pietervanderstar Commented Dec 27, 2020 at 20:43
  • 1 You were the one who confirmed it, you should post an answer and mention your caching solution by name – Tom J Nowell Commented Dec 27, 2020 at 20:53
Add a comment  | 

1 Answer 1

Reset to default 0

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).

本文标签: Enqueued style gets commented if not logged in