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 8
  • acim
    Posted on

    acim acim

    Reply Author

    Under you could possibly fully understand it is important, having that will tactic gives among the list of links while using satisfying site:


  • VIND
    Posted on

    VIND VIND

    Reply Author

    In this webpage it is possible to understand the needs and wants, generate anything exclusive.


  • elegante hosen
    Posted on

    elegante hosen elegante hosen

    Reply Author

    Primary You’re given some sort of brilliant web log. When i resolve be engaged with furthermore consistent a few minutes. when i check out you’re given absolutely incredibly sensible is important, when i resolve possibly be generally making sure your site blesss.


  • Agente de Aduanas
    Posted on

    Agente de Aduanas Agente de Aduanas

    Reply Author

    In this posting fully grasp the most important thing, the product offers you some sort of key word loaded web page link an incredible practical web page webpage:


  • màn hình led
    Posted on

    màn hình led màn hình led

    Reply Author

    On this webpage, you can grasp the requirements and desires and create something exceptional.


  • Sutter Health
    Posted on

    Sutter Health Sutter Health

    Reply Author

    Nice


  • a course in miracles app
    Posted on

    a course in miracles app a course in miracles app

    Reply Author

    For a lot of it can be important, so investigate the web site:


  • rupiah138
    Posted on

    rupiah138 rupiah138

    Reply Author

    In this particular concept internet page, you’ll see the top information, you need to observe above in which higher level regarding factor.