-
-
Save dartiss/2097c32dda644499a40980c517054c0e to your computer and use it in GitHub Desktop.
<?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' ); | |
?> |
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 ?>
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/