Date in top bar being cached

Posted in: Newspaper
Post count: 13

Hello,

I would ask for a little help with caching and showing date in theme’s top bar.
Cached pages are showing date when the page was cached. So if page was cached yesterday it will show yesterdays date. I would like to exclude top bar from caching or maybe change the code from php, to get the right date on page reload?

We’re using WP Rocket currently, but had the same problem with WP Super Cache and Zen Cache as well.

Any suggestions?

Post count: 7909

Hi,

I guess it could be added an exception for site date, but unfortunately I cannot provide a solution for this. The best way is to address this question to the developer of the cache plugin that you use.

Thanks!

Post count: 13

Thank you Alin,

Your demo has the same problem which I guess everyone else who is using this theme have. The top bar isn’t showing the right date when caching is enabled (no matter the plugin).

One way is to get the date with javascript. I’ll post a solution when I find one.

But would be glad if you provide one before I do 🙂

Post count: 7909

Hi,

I have added this on our list and we will change it in a future update, to get the client date instead of server date.

Thanks!

Post count: 13

Here is JS code for date and time which works with cache plugins.
Inserted in date div in top-menu.php.

<script>
function addzero(i) {if (i < 10) { i = “0” + i; } return i; }
function fDate() {
var d = new Date(); var ddd = [“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”]; var dd = ddd[d.getDay()]; var months = [“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”]; var mm = months[d.getMonth()];
document.getElementById(“date”).innerHTML = dd+”, “+d.getDate()+”. “+mm+”, “+d.getFullYear()+” – “+addzero(d.getHours())+”:”+addzero(d.getMinutes())+”:”+addzero(d.getSeconds());
}
setInterval(function fDateI() {
var d = new Date(); var ddd = [“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”]; var dd = ddd[d.getDay()]; var months = [“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”]; var mm = months[d.getMonth()];
document.getElementById(“date”).innerHTML = dd+”, “+d.getDate()+”. “+mm+”, “+d.getFullYear()+” – “+addzero(d.getHours())+”:”+addzero(d.getMinutes())+”:”+addzero(d.getSeconds()); }, 1000);
fDate();
</script>

Date format is localized and it’s showing seconds.

cheers,

  • This reply was modified 10 years by diom.
Viewing 5 posts - 1 through 5 (of 5 total)
The forum ‘Newspaper’ is closed to new topics and replies.