Site logo

Archived topic

How to Add Category In Entry Meta?

1 reply · Started by jaypabs on July 18, 2022

Viewing posts 1–2 of 2

By default, GeneratePress display only date and author name below the title. How can I add category after the author name?

Example:
July 19, 2022 by John in News

Where news is a category of that post.

Hi Jomar,

The easiest approach to control the entire look of the Post meta would be to use Block Element.

Another approach if you’re using the default layout is through a PHP snippet like this:

add_filter( 'generate_post_author_output', function($output){
	
	$categories_list = get_the_category_list( ', ' );
	$mycat = sprintf(
					'<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
					esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
					$categories_list,
					apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
				);
	
	return $output . ' in ' . $mycat;
}, 10, 1);

Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

Hope this helps!

This archived topic is closed to new replies.