Skip to content

Instantly share code, notes, and snippets.

@dartiss
Created November 15, 2017 18:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dartiss/2097c32dda644499a40980c517054c0e to your computer and use it in GitHub Desktop.
Save dartiss/2097c32dda644499a40980c517054c0e to your computer and use it in GitHub Desktop.
WordPress Plugin to List all Site Cookies
<?php
function get_cookies( $paras = '', $content = '' ) {
if ( strtolower( $paras[ 0 ] ) == 'novalue' ) { $novalue = true; } else { $novalue = false; }
if ( $content == '' ) { $seperator = ' : '; } else { $seperator = $content; }
$cookie = $_COOKIE;
ksort( $cookie );
$content = "<ul>n";
foreach ( $cookie as $key => $val ) {
$content .= '<li>' . $key;
if ( !$novalue ) { $content .= $seperator . $val; }
$content .= "</li>n";
}
$content .= "</ul>n";
return do_shortcode( $content );
}
add_shortcode( 'cookies', 'get_cookies' );
?>
@dartiss
Copy link
Author

dartiss commented Nov 15, 2017

Add this to your site's functions.php and then use the shortcode [cookies] on a post or page to display all the site's cookies.

https://artiss.blog/2012/05/wordpress-function-to-list-site-cookies/

@Manja-S
Copy link

Manja-S commented Jun 7, 2018

Thank you for this plugin. It works like a charm. I slightly modified your code as it displayed a lot of superfluous 'n' characters and I preferred to display cookie names in bold font.

One question: here on GitHub you write

Add this to your site's functions.php

whereas your blog says

Add the code below to the functions.php file in your theme folder

What's the correct location for adding your plugin: functions.php in the root folder or functions.php in the theme folder?
Thanks in advance for your answer


Modified code:

<?php // Modified WordPress Plugin to List all Site Cookies from https://gist.github.com/dartiss/2097c32dda644499a40980c517054c0e // Add this to your site's functions.php and then use the shortcode [cookies] on a post or page to display all the site's cookies. function get_cookies( $paras = '', $content = '' ) { if ( strtolower( $paras[ 0 ] ) == 'novalue' ) { $novalue = true; } else { $novalue = false; } if ( $content == '' ) { $seperator = ' : '; } else { $seperator = $content; } $cookie = $_COOKIE; ksort( $cookie ); $content = "<ul>"; foreach ( $cookie as $key => $val ) { $content .= '<li><b>' . $key . '</b>'; if ( !$novalue ) { $content .= $seperator . $val; } $content .= "</li>"; } $content .= "</ul>"; return do_shortcode( $content ); } add_shortcode( 'cookies', 'get_cookies' ); // End of plugin ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment