Site logo

Archived topic

show the categories and the date above the title

9 replies · Started by dmmaso on June 26, 2017

Viewing posts 1–10 of 10

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

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

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

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;
}

Great Tom !! thank you very much again!!

You're welcome :)

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.

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 :)

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.

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
        );
    }
} );
This archived topic is closed to new replies.