the_modified_date
-
Please add, so it can easily be shortcoded for each post. https://codex.ww.wp.xz.cn/Function_Reference/the_modified_date
-
This parameter is added in v4.3. Please do try it and let me know.
Thanks,
Aakashthe one updated today? Does it include <time> tag?
It doesn’t wrap it with time tag. But you can do it manually like this
<time>%%post_modified_date%%</time>Fair enough @vaakash, is it possible to use id conditions to display
%%post_modified_date%%for page A, B and C on page C? Usually based on ID. See my thread on this plugin: https://ww.wp.xz.cn/support/topic/formatting_date_and_time/Would be convenient if your plugin also could display fa-icon before. I already have your plugin in use so would eliminate an extra plugin, thanks!
@vaakash Any answer? 🙂
@alriksson Shortcoder does not support conditional parameters.
Since you’ve asked, you can achieve your requirement using the native WordPress shortcode API itself.
function modified_date_shortcode( $atts ) { $atts = shortcode_atts( array( 'post_id' => '' ), $atts); $date = get_the_modified_date( '', $atts['post_id'] ); return '<i class="far fa-calendar">' . $date . '</i>'; } add_shortcode( 'modified_date_sc', 'modified_date_shortcode' );Paste this in your theme’s function.php file.
Now you can use the shortcode[modified_date_sc post_id="1234"]in your post to get the modified date as per the post ID you pass.Thanks,
AakashGreat @vaakash how could I output it directly into the templates without creating a shortcode? So single no post_id and output it to the templates single.php, post.php etc.
@alriksson I guess you wanted to use the shortcode in theme template file. You can do it like this
<?php do_shortcode( '[modified_date_sc post_id="1234"]' ); ?>Since you want to consider the current post without providing a post id, you have to change the method like below.
function modified_date_shortcode( $atts ) { $atts = shortcode_atts( array( 'post_id' => '' ), $atts); global $post; $post_id = empty($atts['post_id']) ? $post->ID : $atts['post_id']; $date = get_the_modified_date( '', $post_id ); return '<i class="far fa-calendar">' . $date . '</i>'; }@vaakash None of them worked for me.
@alriksson What is the issue ?
Either does not display or displays the php code.
<time datetime=”2019-06-04T15:26:39+02:00″> <i class=”fa fa-calendar” aria-hidden=”true”></i> June 04, 2019</time>
Something like that I want to output if this is the datetime and modified date.
Try this out.
Please note that all your requirement is not related to Shortcoder and I’ve been providing these custom code just to help you and to get you some idea to write your own. For any more custom requirements, I may not be available.
Please do try the code below and I tested it works.
function modified_date_shortcode( $atts ) { $atts = shortcode_atts( array( 'post_id' => '' ), $atts); global $post; $post_id = empty($atts['post_id']) ? $post->ID : $atts['post_id']; $date = get_the_modified_date( 'F j, Y', $post_id ); $date_full = get_the_modified_date( 'c', $post_id ); return '<time datetime="' . $date_full . '"><i class="far fa-calendar"></i> ' . $date . '</time>'; } add_shortcode( 'modified_date_sc', 'modified_date_shortcode' );Shortcode:
[modified_date_sc]or[modified_date_sc post_id="1234"]Thanks,
AakashThe solution I asked for was more towards outputting it on frontend without any shortcode.
But the following will still be very useful and I’m grateful for the help!
The topic ‘the_modified_date’ is closed to new replies.