How can I allow commas in tag names?

I want to allow commas in tag names? For example, "hello, world" or "portland, or" but WordPress keeps separating them. I can do it from the categories page:


And it shows up fine. But anything added from the posts sidebar does not show up ok here:


There is some discussion on it here: but looks like it may not get solved, at least for a while.

In the meantime, I’m looking for an easier solution than adding categories from the categories page.

I’ve tried searching plugins, and didn’t see any that would be helpful. There are a few that deal with replacing commas with other characters when displaying a list of categories, or tags, but I don’t see any plugins that allow the user to replace the default separator.

I don’t care if I have to patch the core myself. Ideally I could write a plugin, but after looking through some of the code I can’t figure out where this gets handled.

Does anybody have a solution, or tips on what functions and javascript to start hacking? I’m not sure where to start looking in the code.


No core hacking needed — thanks to: HOOKS.

Hooks allow to fix the issue with a nice combination of

  • a filter replacing “–” by “, ” before output
  • and an “if” block to make sure the output is not also filtered for the admin interface 🙂
  • and finally, saving all your tags with comma in the format “Fox–Peter” instead of “Fox, Peter”

Here’s the code:

// filter for tags with comma
//  replace '--' with ', ' in the output - allow tags with comma this way
//  e.g. save tag as "Fox--Peter" but display thx 2 filters like "Fox, Peter"

if(!is_admin()){ // make sure the filters are only called in the frontend
    function comma_tag_filter($tag_arr){
        $tag_arr_new = $tag_arr;
        if($tag_arr->taxonomy == 'post_tag' && strpos($tag_arr->name, '--')){
            $tag_arr_new->name = str_replace('--',', ',$tag_arr->name);
        return $tag_arr_new;    
    add_filter('get_post_tag', 'comma_tag_filter');

    function comma_tags_filter($tags_arr){
        $tags_arr_new = array();
        foreach($tags_arr as $tag_arr){
            $tags_arr_new[] = comma_tag_filter($tag_arr);
        return $tags_arr_new;
    add_filter('get_terms', 'comma_tags_filter');
    add_filter('get_the_terms', 'comma_tags_filter');

Maybe some additional details in my blog post to that topic help as well ..


Leave a Comment