Show or Hide Part of your WordPress Post at a Certain Time

After seeing a plugin called CF Expiring Content Shortcode which allows you to hide certain parts of your posts at a set time, I wanted to take it a step further and include the ability to show certain parts of your posts after a set time also.

This function is extremely useful when working with competitions, where you have very specific times that content needs to appear or be hidden.

You could also use this when writing posts if you want to talk about information that’s included in a scheduled post that won’t be available when you first publish your post, so that you don’t have to remember to come back and modify the content after the scheduled post gets published.

So I expanded upon the work of Alex King and Crowd Favorite to produce the following function. Copy this into your functions.php file or your functionality plugin:

Then, in order to use the shortcodes, wrap the text that you want to show or hide in the shortcodes like in the following examples:

Using the shortcodes

Using the shortcode to hide content

You can also use any PHP date or time string in your shortcodes, allowing you to specify exactly when the text is hidden or shown, to the nearest second (providing you’re not using a caching plugin). The date/time must be a valid date/time string in order for the shortcode to work.

I ended up turning this into a plugin (with a whole lot more features) for those who aren’t comfortable messing around with the code. Go and install Show/Hide Content at Set Time if that sounds like you!
Get Show/Hide Content At Set Time (free)

18 thoughts on “Show or Hide Part of your WordPress Post at a Certain Time”

  1. While this tutorial is no doubt very very helpful, is there a plugin that allows us to do the same without editing any parts of our blog?

    1. Yes, at the bottom of my post, I mentioned that I had turned it into a plugin. You can download the plugin from here:

  2. kevin Chard says:

    This is a very interesting idea, I think this would be great snippet for many projects.

    1. Thanks Kevin, I use it on my own sites a fair amount and I’ve also shown my clients how to make use of it. It’s really quite useful.

  3. khalil el haj mousa says:

    hey i want to ask how can i make this show to users once they like my page on facebook?

    1. I don’t know how you can do that on your own site. I’ve done it on Facebook before with FBML, but I don’t know about external sites I’m afraid. If anyone does, feel free to let let us know

  4. Hi Dave,

    I have installed your extremely useful plug-in and enabled shortcodes in excerpts and the content between the “expires” brackets sometimes just leaves a blank space instead of the text I’ve inserted (in my case: “NEW” followed by an em-dash.

    I don’t know understand why it doesn’t work; can you point me in a direction to solve the problem?


    1. Hi Erik,

      Can you tell me whether you left a space either side of the shortcode? Or posted it next to ir within another shortcode? I know that is the cause of these issues sometimes.

  5. Stefano Callisto says:

    Hi there, your plugin it’s a blessing, although i didn’t succeded make it work with a specific time of the day.

    this code works:
    [expires off=”2012-02-01″]iscrizioni aperte fino al 31 Gennaio[/expires]
    [showafter on=”2012-02-02″]1 Febbraio – iscrizioni chiuse[/showafter]

    this code doesn’t work:
    [expires off=”2012-02-01 11:28:00″]iscrizioni aperte fino al 31 Gennaio 11 28[/expires]
    [showafter on=”2012-02-02 11:28:00″]1 Febbraio – iscrizioni chiuse 11.28[/showafter]

    Sorry for the dumb question, i’ve tried all the possible php string for date and time with no success…

    Thanks for this code, anyway!

    1. Hmmm, if you’re sure that the time you were viewing the material should have shown (or hidden) the text, then I’m not sure what’s going on. The syntax looks correct.

      1. Stefano Callisto says:

        ok, i’ll try all the different options…
        Thanks again!

    2. Anuj says:

      Add this within the function code to be able to make it work at a particular time also. date_default_timezone_set(‘Asia/Calcutta’). Timezones can be picked from here

  6. Gerard says:

    I’ve just installed your plugin. I have a question regarding nesting the tags in the event I only want to show some content for a couple of days for example:

    [showafter on=”2012-04-27″][expires off=”2012-04-29″]This content will show for 2 days[/expires][/showafter]

    Will this work?

    1. I’m skeptical, but try it and report back. I’d love to hear if it works!

      1. Gerard says:

        Nope, no such luck.

  7. David says:

    Thanks for such an awesome plugin! I just have a question about the time zone period. Like Stefano, I wasn’t able to get the time set to work, only by the date. Is there a default time zone set? Meaning, I’m currently on eastern time, so when something is set to say, [showafter on=”2012-06-27″] , would it conform to 12am eastern time or something else? Reason I’m asking is because I’ve been testing it out a bit and even when it’s before 12am and it’s set to show the next day, it shows already, but not if i set it to the day after that. Sorry about the long post and hope I haven’t confused you too much! Thanks again!

    1. Hi David, I believe that if you don’t set the time, it will use midnight and it will be based on the time of your server, which may depend on its location and/or its configuration.

      1. David says:

        Thanks for the quick response! I’ll check it out and try playing around with the settings. Thanks for all your help!

Leave a Reply