Useful Snippets

Welcome!


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 Unwanted.cloud

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.

<?php
/**
 * 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()):
    ?>
        <script>
            if(document.cookie && document.cookie.includes('comment_author_')) {
                document.getElementById('wp-comment-cookies-consent').checked = true;
            }
        </script>
    <?php
    endif;
});

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

Comments 13
  • martinnova
    Posted on

    martinnova martinnova

    Reply Author

    Thanks for writing this article. After reading this, this one is really creative.
    brainlevelup


  • test
    Posted on

    test test

    Reply Author

    4334534


  • Ossama
    Posted on

    Ossama Ossama

    Reply Author

    Great work


  • Mike
    Posted on

    Mike Mike

    Reply Author

    thank you guys for sharing


  • welldone
    Posted on

    welldone welldone

    Reply Author

    Introduction First to start things of, let’s get one fact straight We are all human beings Sure we have different tastes and opinions that create th


  • brest
    Posted on

    brest brest

    Reply Author

    are you going to share with us more content google


  • brest
    Posted on

    brest brest

    Reply Author

    are you going to share with us more content google


  • George
    Posted on

    George George

    Reply Author

    Brisket meatball kevin tri-tix sausage. Meatloaf turducken t-bone beef ribs, flank alcatra beef filet mignon drumstick meatball pancetta bresaola buffalo tongue tail.ticketwood


  • Nachhilfe Solingen
    Posted on

    Nachhilfe Solingen Nachhilfe Solingen

    Reply Author

    I especially appreciate that the author also suggests alternative methods to enable this feature if one doesn’t want to work with the WordPress theme. This flexibility allows everyone to choose the solution that best suits their skills and needs.


  • Beste Nachhilfe Solingen
    Posted on

    Beste Nachhilfe Solingen Beste Nachhilfe Solingen

    Reply Author

    All in all, this webpage is a great resource for anyone who owns a WordPress website and wants to automatically enable this feature. I would recommend it to anyone looking for easy ways to improve their website’s usability.


  • Jack Will
    Posted on

    Jack Will Jack Will

    Reply Author

    Dear Stanislav Khromov,
    very useful information for the technocrtas.


  • New York
    Posted on

    New York New York

    Reply Author

    Automatically check the “Save my name, email, and in this browser for the next time I comment.” box in WordPress to save your name, email, and from being changed again. https://www.ticketwood.com/sports/new-york-yankees-tickets/index.php


  • Chicago Cubs
    Posted on

    Chicago Cubs Chicago Cubs

    Reply Author

    You can automatically check the “Save my name, email, and in this browser for the next time I comment.” box in WordPress by ining the search bar at the top of the page and type in “WordPress.” https://www.ticketcover.com/chicago-cubs-tickets/