Set an Expiry Date for WordPress Content

Expiring Content for Web Designers

Introduction

This tutorial will teach you how to apply an expiry date to post content using shortcodes.

This means that you can apply it to anything, from limited special offers to events which will disapear on the date you specify!

Add the following code to the functions.php file of your theme (remeber you should always take a back-up before editing any core files) :


add_shortcode('expire','expire_text');
function expire_text($paras="",$content="") {
   extract(shortcode_atts(array('date'=>''),$paras));
   if ( ($date!="")&&(date("Ymd")>$date) ) {$content="";}
   return $content;
}

With that code installed you can now surround your content with the following shortcode, replacing YYYYMMDD with the date you want the content to expire.

[expire date="yyyymmdd"][/expire]
Here’s a quick example:
[expire date="20120101"]This content will disapear in 2012![/expire]

If you enjoyed this article please consider sharing it!
Credit for developing this code goes to David Artiss
29
Jul 2011
POSTED BY
POSTED IN Web Design Wordpress
DISCUSSION 0 Comments

Creating WordPress Shortcodes

Introduction

Since WordPress 2.5, Shortcodes have been making the lives of Designers, Developers, Clients and amateur bloggers a whole lot easier!

Even now – many WordPress updates later – the shortcode function still remains under-utilised. This tutorial will help you to use shortcodes to their full potential!

We suggest you read up on Shortcodes before beginning to a get a solid idea of how WordPress uses them.

  1. Create a basic shortcode
  2. An advanced shortcode
  3. Subscribe via RSS shortcode
  4. Share on Twitter shortcode
  5. Adsense anywhere shortcode

Read more…

12
Jun 2011
POSTED BY
POSTED IN Web Design Wordpress
DISCUSSION 0 Comments