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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.