How To Change The Date Format in Genesis

There’s 2 ways to change the date format in Genesis which uses the WordPress date format to display the date the post was published. To change the date, you can simply change the format using the WordPress > Settings > General settings:

date-format

Genesis also uses shortcodes to show the date in the entry header. Here’s the default code included in Genesis which creates the post_date shortcode:

add_shortcode( 'post_date', 'genesis_post_date_shortcode' );

function genesis_post_date_shortcode( $atts ) {

	$defaults = array(
		'after'          => '',
		'before'         => '',
		'format'         => get_option( 'date_format' ),
		'label'          => '',
		'relative_depth' => 2,
	);

	$atts = shortcode_atts( $defaults, $atts, 'post_date' );

	if ( 'relative' === $atts['format'] ) {
		$display = genesis_human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ), $atts['relative_depth'] );
		$display .= ' ' . __( 'ago', 'genesis' );
	} else {
		$display = get_the_time( $atts['format'] );
	}

	if ( genesis_html5() )
		$output = sprintf( '<time %s>', genesis_attr( 'entry-time' ) ) . $atts['before'] . $atts['label'] . $display . $atts['after'] . '</time>';
	else
		$output = sprintf( '<span class="date published time" title="%5$s">%1$s%3$s%4$s%2$s</span> ', $atts['before'], $atts['after'], $atts['label'], $display, get_the_time( 'c' ) );

	return apply_filters( 'genesis_post_date_shortcode', $output, $atts );

}

You can filter this shortcode using the genesis_post_date_shortcode filter. To do this you’ll need to spend some time writing and testing a filter function to make sure it works properly.

Here’s the filter function code written & tested for members:

Related Tutorials

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.