添加彩色标签云

边栏彩色标签

function colorCloud($text)
{
  $text = preg_replace_callback('|<a (.+?)>|i', 'colorCloudCallback', $text);
  return $text;
}
function colorCloudCallback($matches)
{
  $text    = $matches[1];
  $color   = dechex(rand(0, 16777215));
  $pattern = '/style=(\'|\")(.*)(\'|\")/i';
  $text    = preg_replace($pattern, "style=\"background:#{$color};$2;\"", $text);
  return "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);
评论
:broken_heart: :confounded: :flushed: :frowning: :grinning: :heart: :kissing_heart: :mask: :pensive: :rage: :relaxed: :scream: :smile: :smirk: :sob: :stuck_out_tongue_closed_eyes: :stuck_out_tongue_winking_eye: :wink: