<?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' ); | |
?> |
This comment has been minimized.
This comment has been minimized.
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
whereas your blog says
What's the correct location for adding your plugin: functions.php in the root folder or functions.php in the theme folder? Modified code:
|
This comment has been minimized.
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/