[Support request] Putting blog post category on top

Home Forums Support [Support request] Putting blog post category on top

Home Forums Support Putting blog post category on top

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #671284
    Margot

    On my blog posts, I want to put the post category above/before the post title. Is there a way I can do this?

    #671409
    Leo
    Staff
    Customer Support

    Hi there,

    Are you wanting to do this on the blog page as well as single posts?

    Let me know πŸ™‚

    #671422
    Margot

    Hi Leo, I’m looking to do this only on single posts. Thanks!

    #671508
    Leo
    Staff
    Customer Support

    Try this PHP snippet here:

    add_filter( 'generate_category_list_output','lh_remove_singlecategories' );
    function lh_remove_singlecategories( $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
    			);
    		}
    	}
    }

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

    Let me know πŸ™‚

    #1420812
    xdexx

    Is it possible to style separately only the Category text? As a black slightly rounded box with white text? The rest of the meta content (author, date) should not be affected.

    Cheers!

    #1420880
    Leo
    Staff
    Customer Support

    Can you open a new topic and link us to the page in question?

    Thanks πŸ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Putting blog post category on top’ is closed to new replies.