I'm trying to output an ordered list of the top five tags for my site into the sidebar.

At the moment, I'm using wp_tag_cloud like this to get it to output a nice <ul>:


However, I'd like it to output as an <ol> instead of a <ul>. Is it possible to do this without hacking the core? Presumably via functions.php or the like?

Also, in the output from wp_tag_cloud, the font size is being set by inline styles. Seeing as I don't need the tag cloud to actually function as a tag cloud, is there any way to simply remove all inline styling from it?

Finally, if there's an easier or less convoluted way of getting an ordered list of tags, please let me know.


1 Answer 1


one possibility: using the 'format=array' and 'echo=0' parameters; and building a foreach loop to output each tag:

  $wptc = wp_tag_cloud('smallest=12&largest=12&orderby=count&order=DESC&format=array&unit=px&number=5&echo=0'); 
  foreach( $wptc as $wpt ) echo "<li>" . $wpt . "</li>\n"; 
  • That does the trick, thanks! Do you know if there's any way to remove the inline styles, also?
    – snthr
    Jun 21, 2011 at 10:01
  • you could use a filter function - added to functions.php of your theme; example: add_filter ( 'wp_tag_cloud', 'no_inline_style_tag_cloud' ); function no_inline_style_tag_cloud( $list ) { $list = preg_replace('/style=("|\')(.*?)("|\')/','',$list); return $list; }
    – Michael
    Jun 21, 2011 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.