{"id":155553,"date":"2011-06-24T08:00:00","date_gmt":"2011-06-24T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/2024\/02\/22\/shortcodes-to-show-or-hide-content\/"},"modified":"2019-10-01T23:45:00","modified_gmt":"2019-10-01T23:45:00","slug":"shortcodes-to-show-or-hide-content","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/shortcodes-to-show-or-hide-content\/","title":{"rendered":"Show\/Hide Content at Set Time"},"content":{"rendered":"<p><strong>Like this plugin?<\/strong> Consider <a href=\"https:\/\/wordpress.org\/support\/view\/plugin-reviews\/shortcodes-to-show-or-hide-content\" title=\"Review Show\/Hide Content at Set Time\" rel=\"ugc\">leaving a quick review<\/a> or writing about how you\u2019ve used it on your site \u2013 <a href=\"https:\/\/www.theukedge.com\/contact\/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=contact\" title=\"Contact Dave\" rel=\"nofollow ugc\">send me a link<\/a> to that write up if you do.<\/p>\n<p>This plugin is maintained on <a href=\"https:\/\/github.com\/theukedge\/shortcodes-to-show-or-hide-content\" rel=\"nofollow ugc\">GitHub<\/a>, so feel free to use the repository for reporting issues, submitting feature requests and submitting pull requests.<\/p>\n<p>This plugin provides shortcodes allowing you to display content or hide content at given dates and times. You can also combine the two to show some content at a given time, and then hide it at another time.<\/p>\n<p>There\u2019s also a separate shortcode if you want to repeat a schedule for showing and hiding content \u2013 for example to only show information about a radio show while it\u2019s on air.<\/p>\n<h4>Usage \u2013 single use<\/h4>\n<p>To show or hide content at one point in time, you can use the <code>[time-restrict]<\/code> shortcode. For example:<\/p>\n<pre><code>[time-restrict off=\"2015-01-01\"]Please enter our competition[\/time-restrict]\n[time-restrict on=\"2015-01-01\"]Sorry, this competition has closed[\/time-restrict]\n<\/code><\/pre>\n<p>If you do not enter a time with the date, it will default to 00:00:00, so in the above example, the first message will show up until 2015-01-01 00:00:00 (i.e. until the first second of 2015) and the second message will show up from 2015-01-01 00:00:00 (i.e. from the first second of 2015)<\/p>\n<p>You can use any date or time string <a href=\"http:\/\/www.php.net\/manual\/en\/datetime.formats.php\" title=\"PHP Date and Time strings\" rel=\"nofollow ugc\">supported by PHP<\/a>, such as:<\/p>\n<pre><code>[time-restrict off=\"September 10th, 2014\"]Will display until 09\/10\/2014[\/time-restrict]\n[time-restrict off=\"2014-09-10\"]Will display until 09\/10\/2014[\/time-restrict]\n[time-restrict off=\"10-Septmber 2014\"]Will display until 09\/10\/2014[\/time-restrict]\n[time-restrict on=\"2014\/09\/10 18:00:00\"]Will show after 09\/10\/2014 at 6pm[\/time-restrict]\n<\/code><\/pre>\n<p>You can also combine starting and ending dates for the same piece of content. So if you want some content to appear between January 1st and January 10th, you could do the following:<\/p>\n<pre><code>[time-restrict on=\"2015-01-01\" off=\"2015-01-11\"]\nThis is a limited time offer\n[\/time-restrict]\n<\/code><\/pre>\n<h4>Usage \u2013 repeating schedule<\/h4>\n<p>To show and hide content on a recurring schedule, you can use the <code>[time-restrict-repeat]<\/code> shortcode. Your options are a daily, weekly, monthly or annual schedule.<\/p>\n<p>A daily schedule takes the following form:<\/p>\n<pre><code>[time-restrict-repeat type=\"daily\" ontime=\"09:00:00\" offtime=\"17:00:00\"]\nWorking 9 to 5\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>Note that you can also cross over midnight, so to only show something from 10PM to 5AM, you can use:<\/p>\n<pre><code>[time-restrict-repeat type=\"daily\" ontime=\"22:00:00\" offtime=\"05:00:00\"]\nFor the night owls\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>A weekly schedule takes the following form:<\/p>\n<pre><code>[time-restrict-repeat type=\"weekly\" onday=\"Monday\" offday=\"Friday\"]\nThe work week\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>You can also specify start and stop times if you want (it will assume starting at 00:00:00 and ending at 23:59:59 if these are left out, like above):<\/p>\n<pre><code>[time-restrict-repeat type=\"weekly\" onday=\"Friday\" offday=\"Monday\" ontime=\"17:00:00\" offtime=\"08:00:00\"]\nIt's the weekend baby!\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>A monthly schedule takes the following form:<\/p>\n<pre><code>[time-restrict-repeat type=\"monthly\" ondate=\"01\" offdate=\"07\"]\nThe first week of the month\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>You can both cross over the end of the month, and apply times to your start and end dates, e.g.<\/p>\n<pre><code>[time-restrict-repeat type=\"monthly\" ondate=\"25\" offdate=\"05\" ontime=\"17:00:00\" offtime=\"08:00:00\"]\nWe are exceptionally busy at the end of each billing cycle. Please bear with us!\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>And lastly, an annual schedule takes the following form:<\/p>\n<pre><code>[time-restrict-repeat type=\"annually\" onmonth=\"June\" offmonth=\"August\" ondate=\"01\" offdate=\"31\"]\nI'm currently in the mountains enjoying the summer!\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>You can cross over the end of the month or even the end of the year, and apply times to your start and end dates, e.g.<\/p>\n<pre><code>[time-restrict-repeat type=\"annually\" onmonth=\"December\" ondate=\"24\" offmonth=\"January\" offdate=\"05\" ontime=\"17:00:00\" offtime=\"08:00:00\"]\nOur employees are currently enjoying time with their families for Christmas. We'll be back after the New Year.\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>If you\u2019re feeling creative, you can even nest shortcodes to account for multiple concurrent conditions. Since you cannot nest shortcodes with the same name, you need to add -2 or -3 to time-restrict-repeat in your shortcode (e.g. <code>[time-restrict-repeat-2]<\/code>).<\/p>\n<p>For example, showing a message during business hours only on Monday to Friday:<\/p>\n<pre><code>[time-restrict-repeat type=\"daily\" ontime=\"08:00:00\" offtime=\"17:00:00\"]\n[time-restrict-repeat-2 type=\"weekly\" onday=\"Monday\" offday=\"Friday\"]\nOur store is currently open\n[\/time-restrict-repeat-2]\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>You can also define a message which should appear if your content is not showing by using the <code>else<\/code> attribute @since 2.5. For example, you could invite people to visit your store during opening hours and ask them come back soon otherwise, like this:<\/p>\n<pre><code>[time-restrict-repeat type=\"daily\" ontime=\"08:00:00\" offtime=\"17:00:00\" else=\"We're currently closed. Come back and see us when we're open.\"]\n[time-restrict-repeat-2 type=\"weekly\" onday=\"Monday\" offday=\"Friday\" else=\"We're currently closed. Come back and see us when we're open.\"]\nOur store is currently open\n[\/time-restrict-repeat-2]\n[\/time-restrict-repeat]\n<\/code><\/pre>\n<p>Note that with nested shortcodes, you need to add the <code>else<\/code> attribute to each shortcode.<\/p>\n<h4>Things to bear in mind<\/h4>\n<ul>\n<li>The time used by the plugin is your site\u2019s local time (check in Settings > General).<\/li>\n<li>The <code>else<\/code> attribute <em>does<\/em> accept HTML, but is restricted by <a href=\"https:\/\/codex.wordpress.org\/Shortcode_API#HTML\" rel=\"nofollow ugc\">WordPress\u2019 limitation on HTML inside shortcode attributes<\/a>.<\/li>\n<\/ul>\n<p>I also run <a href=\"http:\/\/www.doitwithwp.com\/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=my-other-sites\" title=\"WordPress Tutorials\" rel=\"nofollow ugc\">Do It With WordPress<\/a>, which has an array of tutorials for managing, modifying and maintaining your WordPress sites, as well as <a href=\"https:\/\/www.thewpbutler.com\/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=wordpress-services\" title=\"WordPress Maintenance Services\" rel=\"nofollow ugc\">The WP Butler<\/a>, a service for keeping your site maintained, backed up, updated and secure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Shortcodes to wrap around text, which specify at what date or time that content should appear or disappear, either once, or on a recurring basis.<\/p>\n","protected":false},"author":65,"featured_media":342127,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Show\/Hide Content at Set Time - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Shortcodes to wrap around text, which specify at what date or time that content should appear or disappear, either once, or on a recurring basis."},"footnotes":""},"categories":[1],"tags":[7698,593,6140,7459,594],"class_list":["post-155553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-active","tag-date","tag-expire","tag-show-hide","tag-time"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/155553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=155553"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/155553\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/342127"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=155553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=155553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=155553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}