Recently a client requested that they wanted to put an expiry date on a blog post, so the post would be removed from the index and category pages after the offer expired. For SEO purposes, the post would still exist at it’s original URL and be able to be accessed through an archives page.

It’s a really good idea, as many affiliates offering discount codes and offers would find this added function very useful.

A few plugins exists that will “expire” a post, but unfortunately they either delete the post, or move it to a draft version that can only be seen in WordPress admin. This is bad for SEO. Old links expired or not, can still bring in traffic to a website and if a customer missed the offer the first time, they still know they should bookmark the site for the next time around.

SNIPPLR have written a modified version of the WordPress Loop which will remove posts after a date that can be specified in the Custom Fields section of the WP text editor. The code compares an expiry date given with the date from the host server and if the date has passed, the wordpress loop will omit that post from being shown.

The code doesn’t show the posts in the archives however and only expires posts by date when our client needed a to expire a post at a specific time. We modified SNIPPLR’s code so it would do both and also added the ability to adjust the server time, which is handy if your website is hosted in a different timezone to the one you need to use.

All you need to do when writing the post, is enter a custom field with the key “expiration” and set the value in the format: “2010/01/01 18:20:00” – this would expire the post at 6.20pm on the 1st January 2010.

{code type=PHP}***PUT THIS INSIDE THE LOOP, FIRST THING***

$currentdate ) || (is_archive())) { ?>

***THEN PUT THE FOLLOWING LINE AT THE VERY END OF THE LOOP***

{/code}

Share
Share
Tweet
Pin