Tulip Media

Entrepreneurial thoughts

Specify cookie expiration time (or delete them) from WordPress comments

Below WordPress, THE cookie expiration time stored on the computer of the Internet user who commented your blog is extremely long (approximately a year). There are several reasons why a blogger might want to reduce this timeout, starting with improving performance and the desire to have faster page loading. Indeed, one of the pet peeves of bloggers who use the plugin for example W3 Total Cache is the famous mention “Cookie is rejected”, which causes the no caching of pages. In fact, the site is no longer hidden from Internet users who have commented on articles.
Cookies are used to store information about the commentator, which allows them in particular not to fill in the “username”, “email” and “website” fields for each comment. If this option is useful for active commenters, it is much less useful for those who comment rarely, and who find themselves deprived of a cache.
So, for reduce cookie expiration time for commenters, and allow pages to be hidden even for an Internet user who has left a comment on your blog, here is a little hack to add to your sacrosanct functions.php.
[icon style=”chain” color=”red”]functions.php[/icon]
[coded]
add_filter('comment_cookie_lifetime', 'my_comment_cookie_lifetime');
function my_comment_cookie_lifetime($lifetime) {
return 259200;
}
[/coded]
And there you have it, thanks to this little piece of code, you set the cookie expiration time to 259,200 seconds, or 72 hours!
Thanks to Shibashake, where you will find other tips related to W3 Total Cache.
Update :
Since the new EU cookie standards, you are required to have your visitors' permission to store “non-essential” cookies. To avoid pop-ups and other unwanted requests which – let’s face it – are more annoying for the user than the cookie itself, here is a way to delete cookies that store commentator information:
[coded]
remove_action( 'set_comment_cookies', 'wp_set_comment_cookies' );
[/coded]
Obviously add to your functions.php file. Also useful for optimizing your cache!

 

My latest tweets

New shorts on Blooness 👉 Vitality, longevity, weight loss: the ultimate guide to proteins in the keto-Mediterranean diet is online on Blooness. https://buff.ly/3xxNvpj
https://buff.ly/4cG2GM4

New shorts on Blooness 👉 The new premium content comes out in 48 hours, and what content! This will be the most comprehensive guide on the amount of protein to consume on a keto-Mediterranean diet. See you soon !
https://buff.ly/3L2KbFP

New Post: Combo, the best solution to put an end to the headache of scheduling and HR management https://buff.ly/4eE6JtT

Load more

Don't miss business advice by email

No spam, just an email when new content is published.

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEN