• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

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:

Register for full access

Related Tutorials

  • 2 Ways To Modify The Genesis post_date Shortcode

Entry Meta

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags
 

Loading Comments...
 

You must be logged in to post a comment.