This article will show you how to display a random fact on your website using PHP or WordPress shortcode. Not unlike our article on displaying a random quote (which is actually quite decent) and another (scheduled) article on displaying a random insult, they were created simply to make use of our suite of content APIs. In an attempt to establish a presence in the WordPress repository, we submitted the Insult plugin making it, quite possibly, the crappiest plugin WordPress has ever seen. That said, it's found a limited audience and we'll continue to support it.
In migrating our services over to our new website we'll be updating all the APIs to use JSON data almost exclusively.
Most of the facts that we have on record are interesting and valid. Others are crap and we have no idea if they're true. Some of the records are submitted via a few different third-party platforms so we don't have an overly effective way of validating all the submitted data.
The result of the
[fact] shortcode will render something like this (bolding and blockquote is mine):
The best recorded distance for projectile vomiting is 27 feet.
True? No idea.
Copy and paste the WordPress function into your theme's
functions.php file or, if you sensibly have one installed, your custom functions plugin.
The cache period can be defined in your shortcode as
cache="3600" (one hour), or hard-coded into your shortcode function.
Used outside of WordPress the following function can be used. It requires that you include Simple Cache.