Запятые в тегах WordPress - PullRequest
       47

Запятые в тегах WordPress

0 голосов
/ 11 апреля 2019

Я хочу, чтобы в названиях тегов отображались запятые для названий городов, округов и штатов.В настоящее время они разделяются, даже при вводе их в редактор тегов (позже они разделяются при попытке добавить их в сообщение).

Я нашел статью, в которой рассказывается, как обмануть систему с помощью "-"в качестве заполнителя для запятой и использования поиска и замены, чтобы превратить его в запятую.https://www.saotn.org/display-commas-wordpress-tags/ Однако при помещении кода в functions.php и использовании тега с «-» в его имени ничего не происходит.Я вижу знак "-" вместо запятой.

// filter for tags (as a taxonomy) with comma
//  replace '--' with ', ' in the output - allow tags with comma this way
if( !is_admin() ) { // make sure the filters are only called in the frontend
    $custom_taxonomy_type = 'location'; // here goes your taxonomy type
    function comma_taxonomy_filter( $tag_arr ){
    global $custom_taxonomy_type;
    $tag_arr_new = $tag_arr;
    if( $tag_arr->taxonomy == $custom_taxonomy_type && strpos( $tag_arr->name, '--' ) ){
        $tag_arr_new->name = str_replace( '--' , ', ', $tag_arr->name);
    }
    return $tag_arr_new;    
}
add_filter( 'get_' . $custom_taxonomy_type, comma_taxonomy_filter );

function comma_taxonomies_filter( $tags_arr ) {
    $tags_arr_new = array();
    foreach( $tags_arr as $tag_arr ) {
        $tags_arr_new[] = comma_taxonomy_filter( $tag_arr );
    }
    return $tags_arr_new;
}
add_filter( 'get_the_taxonomies', 'comma_taxonomies_filter' );
add_filter( 'get_terms', 'comma_taxonomies_filter' );
add_filter( 'get_the_terms', 'comma_taxonomies_filter' );
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...