Site logo

Archived topic

DATE BEFORE TITLE AND CATEGORIES AFTER

3 replies · Started by Iván on September 21, 2018

Viewing posts 1–4 of 4

Hi! Is there a way of displaying the date before the post title and the categories after it? Thank you so much!!

Hi there,

We'd have to use a few functions for this:

add_filter( 'generate_show_categories', '__return_false' );
add_filter( 'generate_post_date', '__return_false' );

add_action( 'generate_before_entry_title', function() {
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';

    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>' . $time_string;
    }

    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );

    printf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
        sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
            esc_url( get_permalink() ),
            esc_attr( get_the_time() ),
            $time_string
        )
    );
} );

add_action( 'generate_after_entry_title', function() {
    $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );

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

Let me know if this helps or not :)

It works, Leo! You are an awesome team!
Thanks!!

You're welcome :)

This archived topic is closed to new replies.