Halloween Sale 15% off Ends in See the plans
PHP

Cookie List Table Shortcode

Adds a [cookie_list] shortcode that prints a clear table of the cookies your site uses, with provider, purpose and duration, for your cookie or privacy policy page.

Don’t have WPIDE yet? Install it on your site

Code

// Name, provider, purpose, duration.
$wpide_cookie_list = array(
    array( 'wordpress_logged_in_*', 'This site', 'Keeps you logged in.', 'Session or 14 days' ),
    array( 'wp-settings-*', 'This site', 'Remembers editor and admin preferences for logged-in users.', '1 year' ),
    array( 'comment_author_*', 'This site', 'Remembers your name and email for the comment form, if you agree.', '1 year' ),
    array( 'wpide_consent', 'This site', 'Remembers your cookie choice.', '6 months' ),
    array( '_ga, _ga_*', 'Google Analytics', 'Counts visits anonymously, only after you consent.', '2 years' ),
);

add_shortcode( 'cookie_list', function () use ( $wpide_cookie_list ) {
    $html = '<div class="wpide-cookie-table" style="overflow-x:auto"><table><thead><tr><th scope="col">Cookie</th><th scope="col">Provider</th><th scope="col">Purpose</th><th scope="col">Duration</th></tr></thead><tbody>';

    foreach ( $wpide_cookie_list as $row ) {
        $html .= '<tr>';
        foreach ( array_pad( $row, 4, '' ) as $i => $cell ) {
            $html .= 0 === $i ? '<td><code>' . esc_html( $cell ) . '</code></td>' : '<td>' . esc_html( $cell ) . '</td>';
        }
        $html .= '</tr>';
    }

    return $html . '</tbody></table></div>';
} );

Notes

Keep the list in the snippet up to date whenever you add or remove a tool that sets cookies.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.