If you receive a PHP error similar to that above, you’ll need to enable output buffering if you can. This can be done fairly simply by adding the following line to your .htaccess file. (That lives in the root folder of your website: often named /htdocs, /httpdocs or /public_html.)
php_value output_buffering 4096
This instructs PHP not to send data to the browser until the full page has bneen read by the server. (Usually, PHP sends HTML to the browser, processes a PHP block when it comes to one, sends the next bit of HTML and so on.
If you try and instruct the browser to do something while it’s in this mode, unless the instruction is right at the beginning, it’ll be too late, because the browser’s already receiving data. Using the output_buffering setting means PHP waits for the entire HTML page to be parsed before sending the resulting HTML to the browser, with any instructions at the beginning of the page.)
This is a WordPress plugin created to redirect to a given page on a particular day. Let’s say you want certain information to be available on a certain day, like a list of events. Users could go to http://yoursite.com/events, which would then redirect to http://yoursite.com/events/<day>, where <day> is obviously “monday”, “tuesday” etc, depending on what day of the week it is.
There may already be more elegant solutions to this problem, but I wanted to build a WordPress plugin from scratch, rather than adapting an existing one. The much more efficient shortcodes system implemented in WordPres 2.5 (better than lots of plugins performing a find and replace or regular expression check) makes this really easy.
Requirements
This plugin requires WordPress 2.5 or later, as it uses the add_shortcode() helper function.
How to use
- Just download the Zip file, extract it and and upload it to your /wp-content/plugins directory or install it via the Plugins menu in your WordPress dashboard.
- Activate the plugin.
- Visit the page visitors will go to to find the relevant day’s page. In the above example, this would be a page just called Events.
- Use any of the shortcodes documented below to redirect users to relevant pages based on the day of the week.
Shortcodes
There are three options, giving you total flexibility.
-
[[weekday-redirect]]
This very simple option appends the weekday to the current URL. So if that page were available at http://yoursite.com/events, the shortcode would redirect to http://yoursite.com/events/monday, on a Monday, and http://yoursite.com/events/tuesday on a Tuesday.
-
[[weekday-redirect pattern="http://events.yoursite.com/%day/"]]
This dynamic option redirects to http://events.yoursite.com/<day>, where <day> is the day of the week. So for example, the above example would redirect to http://events.yoursite.com/monday/ on a Monday, and http://events.yoursite.com/tuesday/ on a Tuesday. This is useful if you need more control over where the visitor is redirected to. You can use any URL you like: just make sure you include the %day variable.
-
[[weekday-redirect monday="/events/mon/" tuesday="/events/tues/" wednesday="/events/wed/" thursday="/events/thurs/" friday="/events/fri/" saturday="/events/sat/" sunday="/events/sun/"]]
This static option redirects to http://yoursite.com/events/mon/ on a Monday, http://yoursite.com/events/tues/ on a Tuesday and so on. This is useful if you want URLs that don’t have the full weekday in them or if you’re not using slugs but ID numbers in your permalinks, but the slight drawback is you have to supply all of the day URLs.
Order of logic
- The plugin first looks to see if you’re using the
pattern option. If so, that overrides everything else.
- If the
pattern parameter isn’t in use, the plugin checks to see if you’ve defined a URL for the specific day of the week. If it can’t find one, it reverts to the third step.
- If no pattern or URL can be found, it appends the weekday to the end of the URL, ala the first code example above.
License
Who gives a shite? Just use it if you like it!