SHARE
TWEET

advanced tag cloud widget css classes

alchymyth Aug 18th, 2012 175 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter ( 'wp_tag_cloud', 'tag_cloud_widget_advanced_classes' );  
  2.  
  3. function tag_cloud_widget_advanced_classes( $taglinks ) {
  4.         $tags = explode('</a>', $taglinks);
  5.         $regex1 = "#(.*tag-link[-])(.*)(' title.*)#e";        
  6.         $regex2 = "#(.*style='font-size:)(.*)((pt|px|em|pc|%);'.*)#e";
  7.         $regex3 = "#(style='font-size:)(.*)((pt|px|em|pc|%);')#e";        
  8.         $regex4 = "#(.*class=')(.*)(' title.*)#e";        
  9.         foreach( $tags as $tag ) {        
  10.                 $tag = preg_replace($regex1, "('$1$2 tag-slug-'.get_tag($2)->slug.'$3')", $tag ); //add .tag-slug-{slug} class  
  11.                 $size = preg_replace($regex2, "(''.round($2).'')", $tag ); //get the rounded font size      
  12.                 $tag = preg_replace($regex3, "('')", $tag ); //remove the inline font-size style
  13.                 $tag = preg_replace($regex4, "('$1tag-size-'.($size).' $2$3')", $tag ); //add .tag-size-{nr} class
  14.                 $tagn[] = $tag;
  15.         }    
  16.         $taglinks = implode('</a>', $tagn);    
  17. return $taglinks;
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top