David Artiss

WordPress – Making Post/Page Content Expire


Due to updates, over time, that have been made to the site and the age of this article, this post may not display correctly. In particular images may be missing or product reviews display incorrectly.

If this is the case and you'd particularly like me to fix it, then please reach out to me on Twitter.

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…

(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…

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.


Adobe Acrobat Reader Vs Foxit Reader revisited » « Google Android Traction Statistics

6 Comments

  1. 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

    • 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.

  2. Looks like the ability to show content after a date got removed in simplification. I tweaked and came up with a function to do it:

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

    I don’t know a thing about php, but it was pretty obvious what needed to be changed 🙂

    • Hi Rob,

      Yes, my original code was only intended to hide content after an expiry date. Your modification does the opposite – content doesn’t appear until the date specified.

      David.

  3. HI there, wondering if you ever released the plugin mentioned above? If it does what you reckon I’d happily buy it as a premium!

Talk to me!

Copyright © 2017 David Artiss

Theme by Anders NorenUp ↑

Scroll Up
%d bloggers like this: