Skip to content

Instantly share code, notes, and snippets.

@xavivars
Created October 5, 2018 12:06
Show Gist options
  • Save xavivars/0a6ba9aff3d8daa2d1e58ee7d6c4626e to your computer and use it in GitHub Desktop.
Save xavivars/0a6ba9aff3d8daa2d1e58ee7d6c4626e to your computer and use it in GitHub Desktop.
XV Sort Tag Cloud
<?php
/*
Plugin Name: XV Sort Tag Cloud
Description: Sorts properly tag cloud by name (removing accents)
Author: Xavi Ivars
Author URI: http://xavi.ivars.me/
Version: 1.0
License: http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/
add_filter('tag_cloud_sort', function( $tags, $args )
{
if( empty( $tags ) || ! is_array( $tags ) ) {
return $tags;
}
uasort( $tags, '_xv_sort_term_by_name' );
return $tags;
}, 10, 2 );
if ( ! function_exists( '_xv_sort_term_by_name' ) ) {
function _xv_sort_term_by_name($a, $b) {
return strnatcasecmp( remove_accents($a->name), remove_accents($b->name) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment