[Resolved] DATE BEFORE TITLE AND CATEGORIES AFTER

Home Forums Support [Resolved] DATE BEFORE TITLE AND CATEGORIES AFTER

Home Forums Support DATE BEFORE TITLE AND CATEGORIES AFTER

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #682870
    Iván

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

    #683449
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #683583
    Iván

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

    #683865
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.