this is an expected result. when a page is cached, the page is saved as a static html file so PHP and Mysql do not work.
@emrevona
I have the following in functions.php.
add_filter('send_headers',function(){
header('Vary: User-Agent');
});
I expected the header information to be output dynamically as it is not page cached.
Does add_filter not work if static html file is responded?
yes, the add_filter does not work after static html file is created.
you need to do it with Ajax request.
@emrevona
For example, Certainly the following is not reflected while the static html file is being returned.
add_filter('the_content', function(){
return 'Hello!!';
});
However, if we regenerate the page cache, it will be reflected.
Regarding “header information”, since it is not included in the page cache, it will not be reflected even if the static html is regenerated.
My understanding is that this is a sequence issue.
you mean that the code works before creating cache so the “Hello!!” keyword must exist in the html source. right?
@emrevona
the code works before creating cache so the “Hello!!” keyword must exist in the html source
yes, of course.
add_filter('the_content', function(){
return 'Hello!!';
});
Write the above in functions.php and regenerate the page cache, it will be reflected correctly.
add_filter('send_headers',function(){
header('Vary: User-Agent');
});
But in the above case it is not reflected.
Simply put, send_headers is disabled by WP fastest cache plugin.
can you try another cache plugin please?
@emrevona
If I want to add response headers to cached pages, how exactly do I do that?