Created
October 5, 2018 12:06
-
-
Save xavivars/0a6ba9aff3d8daa2d1e58ee7d6c4626e to your computer and use it in GitHub Desktop.
XV Sort Tag Cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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