• Resolved avu

    (@avu)


    Hi,


    The standard post fields ‘post_modified’ or ‘post_modified_gmt’ hour is displayed in 0-12 AM/PM format but with no AM/PM indication.

    Is there a way to show the AM/PM info or adopt the site date / hour display format or show the hour in 24h format ?

    Thanks

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support pdclark

    (@pdclark)

    Below is a shortcode [datetime] which will output the current post object’s modification date according the the date and time format set on /wp-admin/options-general.php.

    The default setting includes am/pm. See https://www.php.net/manual/en/datetime.format.php for guidelines on how to set alternative formats on that settings page, such as 24-hour time.

    See the comments below for links to additional documentation & how to output the published date instead of the modified date.

    The shortcode outputs the timestamp in a <p> tag. If it is to be used within content already in a paragraph or other tag, remove <p> and </p>, or remove return sprintf( and instead start the function at return wp_date(, removing one of the ending-closing-parenthesis.

    <?php
    
    /**
     * [datetime]
     * 
     * @see /wp-admin/options-general.php (For date & time format settings.)
     * @see https://developer.ww.wp.xz.cn/reference/functions/wp_date/
     * @see https://developer.ww.wp.xz.cn/reference/functions/get_post_timestamp/
     * @see https://www.php.net/manual/en/datetime.format.php
     * @see https://www.php.net/manual/en/function.sprintf.php
     */
    add_shortcode(
    	'datetime',
    	function( $atts, $content, $tagname ) {
    		return sprintf(
    			'<p>%s</p>',
    			wp_date(
    				sprintf(
    					'%s %s',
    					get_option( 'date_format' ),
    					get_option( 'time_format' )
    				),
    				get_post_timestamp(
    					get_the_ID(),
    					'modified' // change to 'date' for published date.
    				)
    			)
    		);
    	}
    );
    Thread Starter avu

    (@avu)

    OK, the reference  {@post_modified} in the POD template will be replaced with the shortcode [datetime] whose php code you were so kind to share allows full control of the post ‘date modified’ display format.

    Many thanks !

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Std post field ‘post_modified’ hour display format ?’ is closed to new replies.