how to put last updated date or last modified date WordPress
To display the last updated date or last modified date of a post in WordPress, you can follow these steps. Please note that the method described here assumes you have a basic understanding of WordPress and can access the theme files.
Using Code Snippet (Recommended):
The easiest way to display the last modified date is by adding a code snippet to your theme's functions.php file. This way, you won't lose the changes when updating your theme.
Open your theme's functions.php file (Appearance Theme Editor) and add the following code snippet:
php
function last_updated_date() {
$modified_date = get_the_modified_date('F j, Y');
$output = 'Last updated on ' . $modified_date;
return $output;
}
add_shortcode('last_updated', 'last_updated_date');
Save the changes.
Using Shortcode:
After adding the code snippet to your functions.php file, you can now use a shortcode to display the last updated date anywhere in your posts or pages.
In the post editor, add the shortcode [last_updated] where you want the last updated date to appear. When you publish or update the post, the shortcode will be replaced with the actual last modified date.
Example usage in a post: "This article was last updated on [last_updated]."
Styling (Optional):
You can further style the output by adding CSS to your theme. You can add the CSS to your theme's stylesheet (style.css) or use a custom CSS plugin.
css
.last-updated {
font-style: italic;
color: #888;
}
You can add a class to the shortcode function and wrap the output with a span tag with the class for styling. Modify the shortcode function like this:
php
function last_updated_date() {
$modified_date = get_the_modified_date('F j, Y');
$output = 'span class="last-updated"Last updated on ' . $modified_date . '/span';
return $output;
}
add_shortcode('last_updated', 'last_updated_date');
Now the output will be wrapped in a span with the class "last-updated."
Remember to always backup your theme files or use a child theme before making changes. This ensures that your modifications won't be lost when your theme is updated.
Тэги:
#how_to_put_last_updated_date_or_last_modified_date_WordPress #WordPress_Last_Updated_Date #Last_Modified_Date_Tutorial #WordPress_Date_Shortcode #Display_Post_Modification_Date #WordPress_Last_Edit_Date #Last_Updated_Date_Function #WordPress_Date_Display #Last_Modified_Date_Shortcode #WordPress_Post_Update_Date #Last_Updated_Date_in_Posts #WordPress_Custom_Shortcode #Last_Modified_Date_Functionality #WordPress_Date_Formatting #Last_Update_Date_Tag #WordPress_Code_Snippet