Tag Archives: tell Automattic to add this in the future

How to Make Non-Alphabetical, Sequential Post Tags in WordPress

One thing I didn’t think I’d write about on this blog is code, so here I am writing about code. I wanted WordPress to format my imported Tumblr posts’ tag order. It’s a humorous diversion for myself (and, one hopes, the reader as well).

Turns out, this is not as easy as it would seem. WordPress lists tags alphabetically by default. And I didn’t want to use a plugin for what WP should do naturally. Here’s what I came up with.

There may be better ways to do this—if so, tell me. Otherwise, add this to your functions.php file

$posttags = get_the_tags();
$tagsArray = array();

if ($posttags) {
 foreach ($posttags as $tag)
 {
 $tagsArray[] = $tag->term_id;
 }

$tags = get_tags( array('orderby' => '', 'include' => $tagsArray, 'fields' => 'all' ));

if ($tags) {
 echo '<span class="tags-links">';
 foreach ( (array) $tags as $tag ) {
 $tag_link = get_tag_link( $tag->term_id );
 echo "<a href=\"{$tag_link}\">{$tag->name}</a>"; 
 }
 echo '</span>';
 }
} //end if posttags