Old article notification: report outdated content

Old article notification: report outdated content

How to tell your site visitors that they are on a old article whose content is likely to be out of date? In this article, I’ll show you how to display a notification on WordPress to specify that content may be out of date.

This type of warning on an old article can be useful if your content tends to go out of fashion and are likely to mislead people. This can cause readers to be more vigilant about their use.

Plugins to report an old article

Some WordPress plugins, like Old message notification and Juiz’s obsolete post message, allowdisplay a notification on an old article. However, as of this writing they haven’t been updated in quite a while.

These are “simple” plugins, which fulfill a basic function and therefore do not necessarily have to be updated very often in the same way as more complex plugins. However, they should be used with caution as they are likely to cause errors.

I advise you instead to turn to the method proposed just after, which consists of using a few lines of code to add the same type of notification.

For all intents and purposes, a plugin like Juiz’s obsolete post message offers simple options: you define an expiration period, 360 days by default, after which you consider that the articles may no longer be up to date. This period depends of course on the nature of your content, which goes out of fashion more or less quickly depending on the theme.

You then choose the text of the notification and where it is displayed. And that’s all !

Juiz’s obsolete post message

Old message notification offers a more customizable approach: the plugin creates a checkbox on each article, which allows you to report the content as being out of date and to fill in a custom message. You have to do it article by article, but it has the advantage of letting you choose what you consider to be an “old article”.

Display an old article notification by hand

As I told you, the plugins mentioned are old. So you can use a simple method instead: a few lines of code to copy in the file that controls the display of your articles on your WordPress theme (or your child theme

, if you make your customizations in a child theme as recommended).

Start by connecting to the server where your site is stored, using an FTP client like FileZilla. Go to the folder where your WordPress site is stored (often it’s a folder called “www” or “public_html”). You should see folders named “wp-admin”, “wp-content” and “wp-includes”.

Enter in the wp-content folder, then in “themes”, then in the folder of your theme or child theme.

At first you will open the theme’s style.css file, which controls formatting. You will add a few lines of code to it, which will allow the old article notification to appear aesthetically.

At the end of the style.css file, copy this:

.ancienarticle {
    background: #d0e9ff;
    border:1px solid #ccd0d4;
    padding:10px 15px;
    margin: 20px 10px;

What does this piece of code mean? It defines the background color of our “old article” notification (background), the border that surrounds it with a thickness of one pixel, except on the left (left) where it is 4 pixels. Colors, like “# ccd0d4”, are expressed in hexadecimal notation (if you type “hexadecimal color” on Google, you will access a tool to get the code for a color). We also define the height of the line of text (line height), the spacing between the text of the notification and the border (padding) and the margin surrounding the notification (margin).

The second step is to define what triggers the display of the notification. To do this, we’ll create a simple code that says:

  • An expiry period – Number of days after which you consider that an article is no longer up to date, 730 in my example.
  • This expiration time in seconds – In my example, 730 days with 24 hours a day, 60 minutes per hour and 60 seconds per minute.
  • The current date – We retrieve the current date converted into seconds (the letter U designates the number of seconds since the Unix era, that is to say since January 1, 1970).
  • The last modification date – We then subtract the date on which the article was last modified, in order to know how much time has elapsed between this date and today.
  • The condition – If the result of the calculation is greater than the duration that you have defined as the expiration period, then the notification is displayed.

In php code, it translates like this:

$perime = 730;
$ancienarticle = $perime*60*60*24; 
if((date('U')-get_the_modified_time('U')) > $ancienarticle) {echo '<div class="ancienarticle">Cet article n'a pas été mis à jour depuis un certain temps. Il est susceptible de contenir des informations périmées.</div>';}?>

Warning: if the text of your notification includes an apostrophe, you must precede it with a backslash, otherwise the code will “break” your site. Look at the example provided, and remember to do it for all the apostrophes.

You will have to copy this code where you want the notification to appear. Most of the time, this is a file of your theme called single.php, which controls the display of articles. But it can also have another name if the theme has been personalized, for example “content-single.php”. It can be stored in a subfolder of your theme.

In that file, look for a piece of code that looks like this:

<?php the_title(); ?>

It’s the code that controls display of article title. You can copy the code from the before or after notification, depending on where you want it to appear.

Note that if the title is surrounded by h1 tags, which should normally be the case if the theme is well coded, you will have to place the notification code before or after these tags, but not in the middle.


<?php $perime = 720; $ancienarticle = $perime*60*60*24; if((date('U')-get_the_modified_time('U')) > $ancienarticle) { echo '<div class="ancienarticle">Cet article n'a pas été mis à jour depuis un certain temps. Il est susceptible de contenir des informations périmées.</div>'; } ?><h1><?php the_title(); ?></h1>

Or like this:

<h1><?php the_title(); ?></h1><?php $perime = 720; $ancienarticle = $perime*60*60*24; if((date('U')-get_the_modified_time('U')) > $ancienarticle) { echo '<div class="ancienarticle">Cet article n'a pas été mis à jour depuis un certain temps. Il est susceptible de contenir des informations périmées.</div>'; } ?>

An old article notification, good or bad idea?

I have one mixed opinion on this type of notification, it is for this reason that you do not see any on this blog.

If you are sure that your articles will expire beyond a certain period, this can be of service to Internet users … but ideally, you should also set up a outdated content management process. For example, is it still useful for this content to be referenced if it is no longer relevant? Could they be updated?

In most situations, the age of an article does not necessarily induce an “expiration” of information. An article can be 3 or 4 years old and still quite relevant… just like an article published 6 months ago can already be out of date. I know something about this blog! I have already published an article on a plugin which, a week or two later, completely changed its interface and its options. The whole article was good to redo and yet it was all “fresh”!

The problem with a notification of outdated content is that it signals a decrease in relevance, and therefore in added value of the content for the Internet user. A newbie to the subject, who does not have the knowledge to decide for himself whether an article is still up to date or not, may tend to take the notice at face value and stop reading immediately.

Some people choose, for this reason, to display the notification at the end of the article instead. We can also imagine a diversion. Instead of displaying a message saying that the article “may contain outdated information”, you can encourage the user to notify you of a need for an update.

For example in this form, replacing “URL” with the URL of your Contact page:

<?php $perime = 720; $ancienarticle = $perime*60*60*24; if((date('U')-get_the_modified_time('U')) > $ancienarticle) { echo '<div class="ancienarticle">Cet article n'a pas été mis à jour depuis un certain temps. Si vous pensez qu'il mérite d'être réactualisé, <a href="https://www.notuxedo.com/signaler-ancien-article/URL">contactez-moi</a> pour me le signaler.</div>'; } ?><h1><?php the_title(); ?></h1>

To close this article, I share with you here some tips for update an old article instead of letting it sink into oblivion!

Source link

Leave a Reply

%d bloggers like this: