Hi Waqar,
i picked this 2 snippets from the search here.
add_shortcode('the-modified-author', function( $atts = [], $content=null ) {
return get_the_modified_author();
});
add_shortcode('wpv-post-modified', 'wpv_post_modified_shortcode');
function wpv_post_modified_shortcode($atts) {
static $tempDate = 0;
if (empty($atts['format'])) {
$atts['format'] = get_option('date_format');
}
if( $tempDate < get_the_modified_date('U', true) )
{
$tempDate = get_the_modified_date('U', true);
return date($atts['format'], $tempDate);
}
return '';
}
i tried to use them but this code doesn't work in layout cell.,. any idea why ?
updated on [wpv-post-modified format="d-m-Y h:i:s A (T)"] by [the-modified-author]
update: found updated views shortcode:https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-date
Thank You in advance!
Hi Dee,
Thanks for asking! I'd be happy to help.
I've tested the code of both your shortcodes and they work as expected from a layout cell as well as inside a view.
I would suggest a slight adjustment to the second shortcode though, as the original code won't work if the same shortcode is used twice on a page.
add_shortcode('wpv-post-modified', 'wpv_post_modified_shortcode');
function wpv_post_modified_shortcode($atts) {
if (empty($atts['format'])) {
$atts['format'] = get_option('date_format');
}
if( get_the_modified_date('U', true) )
{
$tempDate = get_the_modified_date('U', true);
return date($atts['format'], $tempDate);
}
}
Important note: These shortcodes will only work if they are used inside a loop, whether its a view or a layout, which mean the current post's ID is available to enclosed functions.
The difference between your custom shortcode "wpv-post-modified" and the builtin shortcode "wpv-post-date" is that first one will show the date and time when a post was last edited, while the second one will show it's published date and time.
regards,
Waqar
My issue is resolved now. Thank you Mr Waqar