Randomizing wp_tag_cloud() in child theme

I’m trying to write a wordpress function code in my child theme that randomizes the words in the word cloud where previously it was alphabetized.

The code Im using is below, which doesn’t work.

//
add_filter('wp_tag_cloud_args', 'my_wp_tag_cloud_args_filter');
function my_wp_nav_menu_args_filter($args) {
    $args['order'] = 'RAND';
    // do something
    return $args;
}
//

I’m able to update the wp_tag_cloud()’s default (‘Order’ = ‘RAND’) args in wp-includes/category-template.php but I know that any changes will get replaced. The change work when in that file.

How can I move those set of changes to my wordpress child theme?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try the tag_cloud_sort hook:

add_filter( 'tag_cloud_sort', 'shuffle_tags', 10, 2 );
function shuffle_tags( $tags, $args ) {
    shuffle( $tags );
    return $tags;
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x