Site logo

Archived topic

Blog Category Above Title

21 replies · Started by Ali Rand on May 10, 2017

Viewing posts 1–15 of 22

Hi, is there a way on the Blog posts page to display the Categories above the Title, instead of the categories appearing after the title and any excerpt.

Thanks,

Ali

Hi there,

Are the categories the only thing you want above the title? What about tags?

On the blog page only, or on the single post pages as well?

Let me know :)

Hi Tom,

Just the categories on the blog page would be helpful.

Thanks.

Give this a shot:

add_filter( 'generate_category_list_output','tu_remove_categories' );
function tu_remove_categories( $categories ) {
	if ( is_home() || is_archive() ) {
		return '';
	}
	
	return $categories;
}

add_action( 'generate_before_entry_title','tu_cats_above_title' );
function tu_cats_above_title() {
	if ( is_home() || is_archive() ) {
		$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
			);
		}
	}
}

Adding PHP: https://docs.generatepress.com/article/adding-php/

Hey Tom,

That code just removes the Categories for me. I added your code via a new Code Snippet fyi.

Hmm, that second function should add them above. Can you link me to the page?

Hmm.. In that second add_action() call, replace generate_before_entry_title with generate_before_content.

Ok, thanks, that moved it above the title. If it's an easy fix, can it be below the featured image? So image, category, title...If not, then no worries. This will work for my next project. Thank you for your time!

That's what that first snippet of code should have done..

I would need to log in to your site to see why that didn't work. If you want me to, feel free to send temp admin login details: https://generatepress.com/contact/

Do you have any custom files in your child theme? The account you sent me doesn't have file editing permissions.

No, all the customizations are in Simple CSS. But you can take out any of them. It was for my working on my past client's website, and it's been transferred over.

Any chance you can allow file editing? Basically I need to see why that before entry title hook isn't firing. It was added a long time ago, so I'm confused as to why it wouldn't work.

How do I enable that?

It's a multisite, so Super Admin is the highest privilege. Does going to My Sites > Network Admin > Themes not allow you to edit the files?

This archived topic is closed to new replies.