Want to allow commas in tag names in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // 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'); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.