Site logo

Archived topic

Remove comma from categories in individual post

5 replies · Started by Roger on July 13, 2021

Viewing posts 1–6 of 6

Hi

How to remove comma from categories in individual post?

This code removed the comma from the files but not from the individual post.

add_filter( 'generate_term_separator', function() {
return ' ';
} );

Hi there,

are you using a Custom Function to move the Category meta above the title?
If so can you share the snippet being used?

Note: When adding code in the forum, before submitting the topic, highlight the code and click the Code button. It will maintain the codes formatting.

Hi Davi,

I used this code to move the category.

add_filter( 'generate_term_separator', function() {
    return ' ';
} );

add_filter( 'generate_category_list_output','lh_remove_categories' );
function lh_remove_categories( $categories ) {
	if ( is_single() ) {
		return '';
	}
	
	return $categories;
}

add_action( 'generate_before_entry_title','lh_single_cats_above_title' );
function lh_single_cats_above_title() {
	if ( is_single() ) {
		$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
		if ( $categories_list ) {
			printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
				_x( 'Categories', 'Used before category names.', 'generatepress' ),
				$categories_list
			);
		}
	}
}

Ok this line of the code:

$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );

Change it to:

$categories_list = get_the_category_list( _x( ' ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );

It worked.

Thanks!

Glad to be of help

This archived topic is closed to new replies.