How to Display the Last Updated Date of Your Posts in WordPress

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated… Read More »

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated date of your posts in WordPress.

How to display last updated date of your posts in WordPress

When You Need Last Updated Date for Posts in WordPress?

Most WordPress themes usually show the date when a post was last published. This is fine for most blogs and static websites.

However, WordPress is also used by websites where old articles are regularly updated (like ours). This last updated date and time is important information for those publications.

The most common example is news websites. They often update old stories to show new developments, add corrections, or media files. If they only added the published date, then their users would miss those updates.

Many popular blogs and websites don’t show any date on their articles. This is a bad practice and you should never remove dates from your blog posts.

Having said that, let’s see how to easily display last updated date for your posts in WordPress.

Displaying Last Updated Date in WordPress

This tutorial requires you to add code to your WordPress files. If you haven’t done this before, then we recommend you to look at our guide on how to copy paste code in WordPress.

Method 1: Show Last Updated Date Before Post Content

You will need to add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = the_modified_time('F jS, Y');
$updated_time = the_modified_time(); 
$custom_content = '<p class="last-updated">Last updated on'. $updated_date . 'at'. $updated_time .'</p>';  
} 

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

This code checks to see if a post’s published date and last modified dates are different. If they are, then it displays last modified date before the post content.

You can add custom CSS to style the appearance of the last updated date. Here is a little CSS that you can use as starting point:

.last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
} 

This is how it looked on our demo website.

Last updated date in post content

Method 2: Add Last Updated Date in Theme Templates

This method requires you to edit specific WordPress theme files. Many WordPress themes now use their own template tags which define how these themes show post meta data like date and time.

Some themes also use content templates or template parts to display posts.

Few simpler themes will use single.php, archive.php, and other template files to show content and meta information.

You will be looking for the code responsible for displaying the date and time. You can then either replace that code with the following code, or add it right after your theme’s date and time code.

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; } 

This is how it looked on our demo site:

Last updated date in post meta

We hope this article helped you learn how to display last updated date of your posts in WordPress. You may also want to see our list of most useful time saving WordPress shortcuts.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

How to Display the Last Updated Date of Your Posts in WordPress

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated… Read More »

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

Do you want to display last updated date for your posts in WordPress? Some websites regularly update their posts and would like to show users when the article was last updated. In this article, we will show you how to easily display the last updated date of your posts in WordPress.

How to display last updated date of your posts in WordPress

When You Need Last Updated Date for Posts in WordPress?

Most WordPress themes usually show the date when a post was last published. This is fine for most blogs and static websites.

However, WordPress is also used by websites where old articles are regularly updated (like ours). This last updated date and time is important information for those publications.

The most common example is news websites. They often update old stories to show new developments, add corrections, or media files. If they only added the published date, then their users would miss those updates.

Many popular blogs and websites don’t show any date on their articles. This is a bad practice and you should never remove dates from your blog posts.

Having said that, let’s see how to easily display last updated date for your posts in WordPress.

Displaying Last Updated Date in WordPress

This tutorial requires you to add code to your WordPress files. If you haven’t done this before, then we recommend you to look at our guide on how to copy paste code in WordPress.

Method 1: Show Last Updated Date Before Post Content

You will need to add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = the_modified_time('F jS, Y');
$updated_time = the_modified_time(); 
$custom_content = '<p class="last-updated">Last updated on'. $updated_date . 'at'. $updated_time .'</p>';  
} 

    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

This code checks to see if a post’s published date and last modified dates are different. If they are, then it displays last modified date before the post content.

You can add custom CSS to style the appearance of the last updated date. Here is a little CSS that you can use as starting point:

.last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
} 

This is how it looked on our demo website.

Last updated date in post content

Method 2: Add Last Updated Date in Theme Templates

This method requires you to edit specific WordPress theme files. Many WordPress themes now use their own template tags which define how these themes show post meta data like date and time.

Some themes also use content templates or template parts to display posts.

Few simpler themes will use single.php, archive.php, and other template files to show content and meta information.

You will be looking for the code responsible for displaying the date and time. You can then either replace that code with the following code, or add it right after your theme’s date and time code.

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p>Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; } 

This is how it looked on our demo site:

Last updated date in post meta

We hope this article helped you learn how to display last updated date of your posts in WordPress. You may also want to see our list of most useful time saving WordPress shortcuts.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Display the Last Updated Date of Your Posts in WordPress appeared first on WPBeginner.

How to Disable RSS Feeds in WordPress

Do you want to disable RSS feeds on your WordPress site? RSS feeds allow users to subscribe to your blog posts. However when building small static websites, you may want to turn off the RSS feeds. By default, there is no option to remove RSS… Read More »

The post How to Disable RSS Feeds in WordPress appeared first on WPBeginner.

Do you want to disable RSS feeds on your WordPress site? RSS feeds allow users to subscribe to your blog posts. However when building small static websites, you may want to turn off the RSS feeds. By default, there is no option to remove RSS feeds in WordPress. In this article, we will show you how to disable RSS feeds in WordPress.

Disable RSS Feeds in WordPress

Method 1: Disable RSS Feeds Using a Plugin

This method is easier and is recommended for beginners.

First thing you need to do is install and activate the Disable Feeds plugin. For more details, see our step by step guide on how to install a WordPress plugin.

The plugin works out of the box and it will start redirecting users to your website when they request an RSS feed.

There are a few settings available for the plugin. You need to visit Settings » Reading page to configure them.

Disable Feeds plugin settings

By default, the plugin will try to redirect users to related content on your site when they request a feed. For example, users requesting a category feed will be redirected to category page. Users trying to access custom post type RSS feed will be redirected to the custom post type archive.

You can change this behavior and show users a 404 error page.

You can also select not to disable the global RSS feed and comments feed. This will allow users to still subscribe to your RSS feed, but there will be no individual category, author, or post comment feeds.

Don’t forget to click on the save changes button to store your settings.

Method 2: Manually Disable RSS Feeds in WordPress

This method requires you edit WordPress files. You can use this method if you are comfortable pasting snippets from web into WordPress.

Simply add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_disable_feed() {
wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );
}

add_action('do_feed', 'wpb_disable_feed', 1);
add_action('do_feed_rdf', 'wpb_disable_feed', 1);
add_action('do_feed_rss', 'wpb_disable_feed', 1);
add_action('do_feed_rss2', 'wpb_disable_feed', 1);
add_action('do_feed_atom', 'wpb_disable_feed', 1);
add_action('do_feed_rss2_comments', 'wpb_disable_feed', 1);
add_action('do_feed_atom_comments', 'wpb_disable_feed', 1);

This code simply returns an error page when someone requests an RSS feed.

Feeds disabled error page in WordPress

We hope this article helped you learn how to disable RSS feeds in WordPress. You may also want to see our list of 15 most annoying things about WordPress and how to fix them.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Disable RSS Feeds in WordPress appeared first on WPBeginner.