10/25/2012 – Still Not solved! Please see below:
My client has a WordPress Tag Cloud (tag array) with tags which include [“] character as well as [The] prefix for some tags. I.e:
"rose"
"autumn"
The Abby
The Cloud
The Elephant
Obviously all the tags enclosed in the quotations marks [“] are sorted on the top of the list and all the words starting with [The] prefix are sorted somewhere around the letter [T] (following the logical ASC order).
It was sprinkled on me that: “All tags (in the WP tag cloud) have to be ordered Ascending but those which contain the [” “] or [The] characters have to be sorted with all other tags in the chronological order, ignoring the [“] and [The] prefix.
I looked into the WP core function:
**function wp_generate_tag_cloud**
but I have no idea where to start. In the raw SQL statement, I could probably use the trim() to filter out the [” “] and [The] characters form the tag cloud array but that is only a thought which I have no idea how to apply.
wp_generate_tag_cloud()
invokes a filter namedtag_cloud_sort
, which can override the sort order specified in the$args
parameter. Thetag_cloud_sort
filter receives an array of tags and the actual$args
parameter passed towp_generate_tag_cloud()
, so it can inspect the full settings of thewp_generate_tag_cloud()
invocation and adjust its behavior accordingly.You could try something like this:
Disclaimer: I’ve written this after only a cursory inspection of the
wp_generate_tag_cloud()
function. I haven’t tested it on a live WordPress installation; I have only verified that the sorting function works correctly on your sample tag cloud:ok so you want to avoid modifying the core code of wordpress… when your client hits the update button after you told him not to, then your going to have to go in and mess with it again.. use action hooks instead. there is conveniently one for hooking into the output for the tag cloud function. add this to your themes functions file
That will atleast get rid of the stuff you dont want. as far as sorting it im not to sure but this should get you on your way. it may be easier to sort it with jquery
If you really want to modify the core code run a foreach loop in the tag array before its formatted and use the str_replaces from above in that loop.. The just run sort() on that array and you should be good. But if it were me i would go with the half solution and not have it alphabetized than to modify the wordpress core
Here’s a thought:
you could copy the original tag_cloud function and create your own on your functions.php.
You make the changes you want to make and add this filter inside the function:
And then create the previous filter to add your function to the hook:
I don’t know if it works, I didn’t test it. What do you think?