Display text or link in WordPress until a certain date (PHP)

Posted in Internet and World Wide Web, Wordpress and CMS on March 16, 2017

If you have some text, or a link, or maybe a calendar event that you want to link to and might expire, you can easily display it and then on a certain date remove that information (actually hide it) using some PHP code. You can do this on any PHP page, but if you're using wordpress and you want it in a widget you should download a plugin that handles PHP code like the "Executable PHP widget" but many are available.

Here's the PHP code:

Change the date to the day you want the link or text hidden. It will be using the server date and time. Let's say you want the link or text to expire on Jan 05, 2020 then you would use this code.

<?php if(strtotime('2012-01-01') > time()): ?>
Put your text or link here
<?php endif; ?>

Leave a Reply

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