[Resolved] show the categories and the date above the title

Home Forums Support show the categories and the date above the title

This topic contains 9 replies, has 3 voices, and was last updated by  Tom 1 week, 1 day ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #339561

    Daniel

    Hi,
    There is some way in the blog page and in the pages of a single post to show the categories and the date above the title, in this order.

    Thank you

    Daniel

    GeneratePress 1.3.48
    GP Premium 1.3.1
    #339689

    Tom Lead Developer

    What about the author and tags? Do you want them to appear above as well?

    #339817

    Daniel

    No. I just want category, date and title in this order

    #340500

    Tom Lead Developer

    First, we’d need to move it above the title:

    add_action( 'after_setup_theme','tu_move_posted_on' );
    function tu_move_posted_on() {
        remove_action( 'generate_after_entry_title', 'generate_post_meta' );
        add_action( 'generate_before_entry_title', 'generate_post_meta' );
        add_filter( 'generate_category_list_output', '__return_false' );
    }

    Then you’d need to do this:

    add_filter( 'generate_post_date_output', 'tu_categories_to_date' );
    function tu_categories_to_date( $output ) {
        $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
        $categories_list = sprintf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
            _x( 'Categories', 'Used before category names.', 'generatepress' ),
            $categories_list
        );
    
        return $categories_list . $output;
    }
    #340545

    Daniel

    Great Tom !! thank you very much again!!

    #340773

    Tom Lead Developer
    #645077

    Iain

    Hi Tom I just want to move category & tags above title. I have date and author at bottom of post, I can’t seem to make this work.

    #645360

    Tom Lead Developer

    I wonder if you could do something as simple as this:

    remove_action( 'generate_after_entry_content', 'generate_footer_meta' );
    add_action( 'generate_before_entry_title', 'generate_footer_meta' );

    Let me know 🙂

    #645619

    Iain

    It works but includes all the meta data, rather than just category and tag, and it doesn’t remove the bottom. I’ll keep trying.

    #645837

    Tom Lead Developer

    Let’s try this instead then:

    add_filter( 'generate_show_categories', '__return_false' );
    add_filter( 'generate_show_tags', '__return_false' );
    
    add_action( 'generate_before_entry_title', function() {
        $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="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', // WPCS: XSS ok, sanitization ok.
                esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
                $categories_list
            );
        }
    
        $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
        if ( $tags_list ) {
            printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', // WPCS: XSS ok, sanitization ok.
                esc_html_x( 'Tags', 'Used before tag names.', 'generatepress' ),
                $tags_list
            );
        }
    } );
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.