internet

How to Set an expiration date on your WordPress Articles

To specify a deadline for publication in WordPress is not easily available. Sometimes you might need a set an expiration date on your WordPress Articles and below we have mentioned a small tutorial that will guide you through.

There exists mainly two methods or techniques for adding this functionality (expiration date) on your wordpress articles.

Method 1 – Using the plugin Post Expirator

Although I am not a big fan of using a plugin in all cases, we must admit that this is by far the easiest solution to have a function of deadline for your articles.

Go to the Extensions menu and enter post expirator. Once the desired “post expirator” will found in plugins search menu. Click on Install Now.

After installing this plugin, in the setting options of this plugin you will find an information box will now be displayed in each of your articles, you can set an expiration date.

Method 2 – Using a PHP hack

CHANGING THE WORDPRESS LOOP

This technique is by far the most complicated – it is mainly for advanced users.

We need to change the WordPress loop to insert conditions display items according to the expiration date. Since the loop is used in most of the theme files, we will remain on the index.php.

Within the latter, replace the loop by the following lines of code that have been tested on the Twenty Ten Theme:

Snippet Code

$ today) {$ valid = “yes”} else {$ valid = “no”;}

if ($ valid == “yes”) {

/ / Code of the loop whose title, excerpt, etc..
the_title ();
the_excerpt ();

}
endwhile;
endif;
?>

ADDING A CUSTOM FIELD

The operation of this hack is simple. Specify a custom field with key expiration in each of your items and specify a date format DD / MM / YYYY as value.

Leave a Reply

Your email address will not be published. Required fields are marked *