Tag cloud alphabetical order and french É special character

[ad_1]

Did you specify something like wp_tag_cloud(['orderby'=>'name',]); to generate the cloud? (it appears so)

We would think that since you have your site set to French, that French collation would apply, but there is apparently something off with how PHP locales are configured. (the cloud collation is according to uasort( $tags, 'strnatcasecmp' );, strnatcasecmp() being the native PHP comparison function)

All I can suggest is you use the ‘tag_cloud_sort’ filter to uasort() the tags using a custom comparison function that properly handles É and similar characters.

Hi @bcworkz ,

Thanks for your answer

I just added the Cloud Tag Block to my page,
I didn’t use any tag cloud function or hook in my functions.php

Strange

I will try to deactivate all the plugins, one by one, to see if it could be a conflict

Well, I deactivated the plugins one by one, but it did not change anything.

I noticed that the Post Tags Block is working fine (not placing É after Z letter)
I have the problem only with the Tag Cloud Block…

I tried with Twenty Twenty Four Theme on another website that does not any plugin installed : same problem.

  • This reply was modified 4 hours, 21 minutes ago by charlie67p.
  • This reply was modified 4 hours, 2 minutes ago by charlie67p.

OK, I still don’t know why the Tag Cloud Block does not work,
but I fixed with this !!

/*
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) );
    }
}
  • This reply was modified 25 minutes ago by charlie67p.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer