Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at

RSS Latest posts from my personal blog

Most viewed posts

Subscribe to RSS feed

Automatically check the “Save my name, email, and website in this browser for the next time I comment.” box in WordPress

Stanislav KhromovStanislav Khromov

Surprisingly WordPress always seems to leave the box unchecked when loading a page, so a user has to keep checking it each time they want to leave a comment to keep their name saved. With this simple JavaScript snippet the checkbox will be prefilled if a user has previously checked it and submitted a comment.

 * Automatically tick the "Save my data in this browser" checkbox on comments if it was ticked before.
add_action('wp_footer', function() {
    if(is_single() && comments_open()):
            if(document.cookie && document.cookie.includes('comment_author_')) {
                document.getElementById('wp-comment-cookies-consent').checked = true;

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
Twitter Profile
Visit my other blog

Comments 1
  • leo
    Posted on

    leo leo

    Reply Author

    Very useful, learned from it