Below, you’ll find a detailed guide on how to add the WP Last Modified Info Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Last Modified Info Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the WP Last Modified Info Plugin and the shortcodes it provides:
"WP Last Modified Info is a vital WordPress plugin that efficiently keeps track of when your content was last modified, providing a transparent update history to your audience."
- [lmt-post-modified-info]
- [lmt-template-tags]
- [lmt-site-modified-info]
WP Last Modified Info [lmt-post-modified-info] Shortcode
The wp-last-modified-info plugin shortcode, ‘lmt-post-modified-info’, is used to display the last modified information of a post. It fetches the post’s ID, template, date format, date type, schema, author ID, archive visibility, filter IDs, and gap. If these attributes are valid, it generates the last modified info based on the given template. If the time difference between the post’s published and modified timestamps is less than the specified gap, it won’t display the info.
Shortcode: [lmt-post-modified-info]
Parameters
Here is a list of all possible lmt-post-modified-info shortcode parameters and attributes:
id
– The unique identifier of the post.template
– The layout used to display the last modified info.date_format
– The format of the date when the post was last modified.date_type
– The style of the date when the post was last modified.schema
– Enables or disables JSON-LD markup for the post.author_id
– The unique identifier of the author who last modified the post.hide_archive
– Hides the last modified info on specified archive pages.filter_ids
– Excludes specified posts from displaying the last modified info.gap
– The minimum time gap required between publication and modification to show the info.
Examples and Usage
Basic example – Display the last modified info of a post using its ID.
[lmt-post-modified-info id=1 /]
Advanced examples
Display the last modified info of a post using a specific template and date format.
[lmt-post-modified-info id=1 template="Last updated on: {date}" date_format="F j, Y" /]
Hide the last modified info on certain archive pages (categories, tags, date archives, etc.) by specifying their functions.
[lmt-post-modified-info id=1 hide_archive="is_category,is_tag" /]
Exclude the last modified info on specific posts or pages by specifying their IDs.
[lmt-post-modified-info id=1 filter_ids="2,3,4" /]
Display the last modified info only if the post has been modified after a certain time gap (in seconds) from the published time.
[lmt-post-modified-info id=1 gap=3600 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [lmt-post-modified-info]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'lmt-post-modified-info', [ $this, 'render' ] );
Shortcode PHP function:
function render( $atts ) {
global $post;
if ( ! $post instanceof \WP_Post ) {
return;
}
if ( ! $this->is_enabled( 'enable_last_modified_cb' ) ) {
return;
}
$author_id = $this->get_meta( $post->ID, '_edit_last' );
if ( $this->is_equal( 'show_author_cb', 'custom', 'default' ) ) {
$author_id = $this->get_data( 'lmt_show_author_list' );
}
$atts = shortcode_atts( [
'id' => $post->ID,
'template' => $this->get_data( 'lmt_last_modified_info_template' ),
'date_format' => $this->get_data( 'lmt_date_time_format', get_option( 'date_format' ) ),
'date_type' => $this->get_data( 'lmt_last_modified_format_post', 'default' ),
'schema' => $this->get_data( 'lmt_enable_jsonld_markup_cb', 'disable' ),
'author_id' => (int) $author_id,
'hide_archive' => '',
'filter_ids' => '',
'gap' => $this->get_data( 'lmt_gap_on_post', 0 ),
], $atts, 'lmt-post-modified-info' );
$get_post = get_post( absint( $atts['id'] ) );
if ( ! $get_post ) {
return;
}
if ( ! empty( $atts['hide_archive'] ) ) {
$archives = explode( ',', $atts['hide_archive'] );
if ( ! empty( $archives ) ) {
foreach ( $archives as $archive ) {
if ( is_callable( $archive ) ) {
if ( $archive() ) {
return;
}
}
}
}
}
if ( ! empty( $atts['filter_ids'] ) ) {
if ( is_singular( explode( ',', $atts['filter_ids'] ) ) ) {
return;
}
}
if ( empty( $atts['template'] ) ) {
return;
}
$published_timestamp = get_post_time( 'U', false, $get_post );
$modified_timestamp = get_post_modified_time( 'U', false, $get_post );
if ( ( $modified_timestamp - $published_timestamp ) < $atts['gap'] ) {
return;
}
$date_type = $this->do_filter( 'post_datetime_type', $atts['date_type'], $get_post->ID );
$timestamp = human_time_diff( $modified_timestamp, current_time( 'U' ) );
if ( $date_type == 'default' ) {
$timestamp = $this->get_modified_date( $atts['date_format'], $get_post );
}
$timestamp = $this->do_filter( 'post_datetime_format', $timestamp, $get_post->ID );
$template = $this->generate( $atts['template'], $get_post->ID, $timestamp, $atts['author_id'] );
return $this->wrapper( $template, $get_post->ID, true, false, 'sc' );
}
Code file location:
wp-last-modified-info/wp-last-modified-info/inc/Core/Frontend/Shortcode.php
WP Last Modified Info [lmt-template-tags] Shortcode
The WP Last Modified Info shortcode, ‘lmt-template-tags’, retrieves the last modified information of a post. This shortcode uses two optional attributes: ‘escape’ and ‘only_date’. If ‘escape’ is set to true, it sanitizes the output. If ‘only_date’ is true, it returns just the date of the last modification.
Shortcode: [lmt-template-tags]
Parameters
Here is a list of all possible lmt-template-tags shortcode parameters and attributes:
escape
– If set to true, it sanitizes the output, useful to prevent security issues.only_date
– If set true, it shows just the date of last modification, not the time.
Examples and Usage
Basic example – Displays the last modified information of the post or page without any formatting or date only parameters.
[lmt-template-tags]
Advanced examples
Display the last modified information with escape parameter. This will escape the output, making it safe for use in HTML.
[lmt-template-tags escape=true]
Show only the date of the last modification, without any time information.
[lmt-template-tags only_date=true]
Combining both parameters to display only the date of the last modification in a safe format for HTML.
[lmt-template-tags escape=true only_date=true]
PHP Function Code
In case you have difficulties debugging what causing issues with [lmt-template-tags]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'lmt-template-tags', [ $this, 'render_template_tags' ] );
Shortcode PHP function:
function render_template_tags( $atts ) {
$atts = shortcode_atts( [
'escape' => false,
'only_date' => false,
], $atts, 'lmt-template-tags' );
return get_the_last_modified_info( $atts['escape'], $atts['only_date'] );
}
Code file location:
wp-last-modified-info/wp-last-modified-info/inc/Core/Frontend/Shortcode.php
WP Last Modified Info [lmt-site-modified-info] Shortcode
The WP-Last-Modified-Info plugin shortcode, ‘lmt-site-modified-info’, retrieves and displays the last modification date and time of the entire website. This shortcode is versatile, allowing customization of date and time formats.
Shortcode: [lmt-site-modified-info]
Examples and Usage
Basic example – The shortcode displays the last modified date and time of the site. The format of the date and time is determined by the default settings of your WordPress site.
[lmt-site-modified-info /]
Advanced examples
The shortcode can be customized by adding parameters. For example, you can change the format of the date and time displayed. In the following example, the format is set to ‘F j, Y @ g:i a’, which will display the date in the format ‘Month Day, Year @ Hour:Minute AM/PM’.
[lmt-site-modified-info format='F j, Y @ g:i a' /]
You can also use the shortcode to display only the date or only the time. In the following examples, the format is set to ‘F j, Y’, which will display only the date, and ‘g:i a’, which will display only the time.
[lmt-site-modified-info format='F j, Y' /]
[lmt-site-modified-info format='g:i a' /]
Please note that the format parameter accepts any valid PHP date format string.
PHP Function Code
In case you have difficulties debugging what causing issues with [lmt-site-modified-info]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'lmt-site-modified-info', [ $this, 'render_global' ] );
Shortcode PHP function:
function render_global( $atts ) {
$option = get_option( 'wplmi_site_global_update_info' );
if ( $option === false ) {
return;
}
$atts = shortcode_atts( [
'format' => get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ),
], $atts, 'lmt-site-modified-info' );
return date_i18n( $atts['format'], $option );
}
Code file location:
wp-last-modified-info/wp-last-modified-info/inc/Core/Frontend/Shortcode.php
Conclusion
Now that you’ve learned how to embed the WP Last Modified Info Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply