Into the (open) source


WordPress: warn the reader that the post is old


Often (writing software and technology) that the article is now present, tomorrow has already passed. There is at least un plugin per WordPress to notify the reader that the post you're reading was written long ago, that is a perfect solution and ready for use, groped but I also wanted to change the code of my theme to add this simple function automatically.

I state that the following steps create a box (in this case yellow) before the title of the article. The user will be informed immediately about upgrading Article, as in the following screenshot, taken from an old article.


It must be said also that with a little ingenuity we can only show this warning in the post relating to a certain category. Well, the premises are finished.

Change the theme

First you need to edit the file "single.php" and "style.css" related to the theme used. To do this, within our administrative panel click on "Appearance" - "Editor".


Depending on the active theme on the blog we have to find the exact point at which to place the following PHP code (immediately above the title Post):

    // date('U')          = Current date in seconds since 1 January 1970 (Unix time)
    // get_the_time('U')  = Date of publication of the article in seconds 1 January 1970 (Unix time)
    // 31557600           = Seconds in a year (365 days and 6 hours)
    if ((date('U') - get_the_time('U')) >= 31557600 && in_category('16')) { ?>
        <div class="notice">
		<h1 class="title">Caution!</h1>
		<p>This article was written in the <strong><?php the_time('Y'); ?></strong>, there may have been some developments in the subject matter.<br />
		If in doubt, leave a comment at the bottom of the article.<br />
		Thank you.</p>
<?php } ?>

The code is well commenato and explanatory only. In this case the box will be shown if the post is older than a year and if it is in category "16" (which in my case corresponds to the category "software". You can also remove the code "&& in_category('16')" if we want the alert to appear in all categories.

The style of the CSS is just as easy, the following lines can be added in any part of the file "style.css":

border-top:3px solid # e6d62e;
border-bottom:3px solid # e6d62e;
padding: 10px 20px 0 10px;

Find a category

Finding the ID number on the category is equally simple. We go to the menu "Goods" - "Categories".


Now pass the mouse on the relevant category, and pay attention to the link associated (lo entertainment at bottom of page).


If we are careful we will read in the data for the variable "&tag_ID=". In my case "16".


I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

  • Thank you, stopsatgreen, for your kind comment.

  • stopsatgreen

    Works a treat. Many thanks!