• Resolved inmiddleburymagazine

    (@inmiddleburymagazine)


    The date bars on the posts show the number of hours/days since posted, rather than the date of the post. Is there a way to change this?
    Website: inMiddlebury.com

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Kathryn Presner

    (@zoonini)

    You can make this change in a child theme, so your tweaks won’t be overwritten when you update the theme. If you’re new to child themes, you can explore these guides:

    https://codex.www.ads-software.com/Child_Themes
    https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/
    https://vimeo.com/39023468

    Keeping your theme up-to-date is strongly recommended to ensure you get bug fixes, security updates, and updates to keep the theme compatible with WordPress core.

    Once your child theme is set up, you’ll need to copy the posted_on() date function from /inc/template-tags into your child theme’s functions.php file:

    function apostrophe_posted_on() {
    		$human_time = apostrophe_human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) );
    		$regular_time = get_the_time( get_option( 'date_format' ) );
    
    		$output_time = sprintf( '%s <span style="display:none;">%s</span>', esc_html( $human_time ), esc_html( $regular_time ) );
    
    		if ( current_time( 'timestamp' ) > get_the_time( 'U' ) + 60 * 60 * 24 * 14 ) {
    			$output_time = esc_html( $regular_time );
    		}
    
    		printf( '<a class="entry-date published" href="%s">%s</a>', esc_url( get_permalink() ), $output_time ); // WPCS: XSS OK.
    		printf( '<time class="updated" datetime="%s">%s</time>', esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ) );
    		printf( '<span class="byline vcard"><a class="url fn n" href="%s">%s</a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), get_the_author() );
    	}
    // endif;

    Change this line from:

    printf( '<a class="entry-date published" href="%s">%s</a>', esc_url( get_permalink() ), $output_time ); // WPCS: XSS OK.

    to this:

    printf( '<a class="entry-date published" href="%s">%s</a>', esc_url( get_permalink() ), $regular_time ); // WPCS: XSS OK.

    That should eliminate the relative dates and give you full dates, no matter when something was posted.

    Let me know how it goes.

    Thread Starter inmiddleburymagazine

    (@inmiddleburymagazine)

    Thank you for the information!

    Based on the images in the theme details, I thought maybe there was something that needed to be checked, or unchecked. I am very new to this, and think that the fix may be above my current skill set. I’m very happy with the theme so far, so I guess I just leave it the way it is for now. Will study-up and try to make the changes later.

    Moderator Kathryn Presner

    (@zoonini)

    OK, sure!

    For your info, Apostrophe designed to display relative dates for posts up to two weeks old. Posts older than that should display full dates.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Date Bars on posts’ is closed to new replies.