Considering how regularly new versions of Firefox now come along, that's quite some bug fix list in version 10! http://t.co/K3I2vLpW 1 week ago

2nd
Jun 10

WordPress – Making Post/Page Content Expire



closeThis post was written 1 year 8 months 12 days days old, so is a bit old now. Feel free to read and comment on this post, just remember some things change with time and any facts in this post may not be accurate anymore.

There are some excellent plugins available to allow you to make time sensitive posts and pages expire. However, these work for the entire post/page rather than just a section.

Here’s the simple solution – a shortcode that you wrap around some content and allows you to specify a date on which it should expiry and simply not display anymore.

Add the following code to your functions.php file in your theme folder…

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

(The above code has been simplified since the post was originally created)

Now, simply add [expire date="yyyymmdd"][/expire] around any text you wish to expire – change yyyymmdd to a date in that format.

For example…

[expire date="20101231"]It's 2010![/expire]

This will display the message “It’s 2010!” until after 31/12/2010.

This is the quick solution – a much fuller version, with expiry time as well as the ability to get content to appear on a specific date/time, will be released as a plugin soon.

Delicious Digg Facebook LinkedIn Read It Later reddit StumbleUpon Twitter SeparatorEmail Google Translate PDF Online Print Friendly

2 Comments

  1. SEOrocks says:

    Hiya

    Many thanks for sharing the above method.

    is there a way to display a message replacing the section that will be removed after the date has expired? for example: This Event is no longer Available – check back later

    Thanks in advance
    S

    • David says:

      Yes. As well as making content disappear after a set time, you can also make content appear when you want – so you could use the shortcode to make one section disappear and then use another shortcode to make the next bit of content appear. The instructions gives full detail on how to use both of these methods.

No Pingbacks/Trackbacks

    Leave a Comment

    All comments are approved manually. No spam please, or comments that add nothing to the conversation.

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

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>