Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Deactivate Cookie #263140
    Johannes Strodl
    Participant

    You can remove any cookie by modifying the HTTP header before it is send to the client.

    1) Create a child theme from your theme. (There are several excellent tutorial on the web which explains the creations of child themes. It is very easy.)
    2) Create a "functions.php" file in the root directory of your new child theme.
    3) Add a hook in "functions.php" for wordpress to modify the HTTP header before it is send:

    
    <?php
    // filter cookies
    function my_remove_cookies($headers) {
        if (isset($_COOKIE['newsletter'])) {
            unset($_COOKIE['newsletter']);
            setcookie('newsletter', null, -1, '/');
        }
        return $headers;
    }
    add_filter('wp_headers', 'my_remove_cookies');
    

    This will remove the cookie named "newsletter". The cookie will never be published to the client. Beware if you use a caching plugin for wordpress. Sometimes the cached page can't be changed by the "wp_headers" hook any more. Then deeper studies of the caching machinery is needed to remove the header part of the cookie.

    When i have time, i will create a plugin to remove cookies by name. Maybe this is a needful thing for such problems.

    Greetings,
    Johannes

Viewing 1 post (of 1 total)