How to Display the Last Updated Date on Your Website Using a Shortcode

Shortcode - WpScriptly

To keep your content fresh and let your readers know when it was last revised, you can add a “Last Updated” date to your pages or posts. By using a simple shortcode, you can easily include this information anywhere on your website. Below is an example of how to implement this feature using a shortcode


.time{
    font-weight:bold;
    color:#070537;
}

Place this coding inside code ssnippet plugin. I personally use Fluent snippet.

*This line will display Apr · 2024. you can change the 

( 'M · Y' )

to match your wordpress settings in the settings → General 

// Define the shortcode function
function current_date_shortcode() {
    // Get the current date
    $current_date = date_i18n( 'M · Y' );
    // Style for the displayed date
    // Return the current date with inline style
    return '<span class="time">' . $current_date . '</span>';
}
// Register the shortcode
add_shortcode( 'current_date', 'current_date_shortcode' );

The short code is

 [current_date]

I recomend placing this in a paragraph or a shortcode block.

Example: Last Updated: Last edited: Jun · 2024

Live example is: https://wpscriptly.com/tos/ at the bottom.

Use as is

Notes:

Wp Scriptly

This basic script, CSS style, and plugin are designed to function optimally assuming minimal interference from your theme or other plugins. If conflicts occur or further customization is needed, additional adjustments may be necessary. Please note that this script, CSS style, or plugin must be used AS IS.

Wp Scriptly

The WpScriptly Monthly newsletter offers top insights for WordPress pros: new scripts, plugins, resources, tips, tools, updates, and more every month.

Sidebar Subscribe

Comments: