Home API Display a Random Quote on your Website with WordPress Shortcode

Display a Random Quote on your Website with WordPress Shortcode


A few years ago we toyed around with the idea of submitting a few plugins to the WordPress repository. Most of them were very basic simply so we could wrap our heads around the way they the WP system worked. One of the first plugins we submitted was QOTZ – a really simple plugin that’d do nothing except render a random quote on your WP website. The plugin is partnered with an unmonitored website, Twitter account , and Facebook page (all displaying the quotes as images rather than text).

A lot of what we worked on a few years ago included an XML API. While we thought XML data was appropriate at the time (mainly because it was browser-readable), history has since educated us on our wayward ways. As we rebuild a number of our websites, any API will return JSON data almost exclusively – now sensibly our norm. This post will essentially reproduce what we once shared on another site: how to render a random quote in your website with shortcode (using our newer, improved, faster, and more reliable API). The plugin update will follow.

If you’re a client and have an API key, check the platform for expanded usage (such as text search, branded image quotes, quotes by author, and paginated results).

The Result

The result is as advertised: a random quote. Shortcode of [qotz] will return the following (bolding and blockquote is mine):

"It is truer to say that martyrs create faith more than faith creates martyrs." — Miguel de Unamuno

The quote is cached on your end for 15 minutes. That ensures you don’t retrieve the same cached quote on our end.

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

PHP Function

Used outside of WordPress the following function can be used. It requires that you include Simple Cache.


  • Most of what’s quoted on the Internet is what we wanted people to say, not what they actually said. Einstein and Marilyn Monroe are probably two of the hardest hit by distorted or fake attribution. However, short quotes are often a paraphrased sentiment, giving them a certain truth.
  • The quote can obviously be formatted with HTML to your liking.
  • Clients have access to a huge database of quotes in our library that can all be manufactured into custom images. Once created, they can be sent to social in a number of ways.
  • Despite showing a small number of downloads, we will build upon this plugin to return movie quotes and other information.


The plugin version of QOTZ is maintained on WordPress.

Plugin Title: QOTZ Author: beliefmedia
Description: Qotz is a very simple plugin that’ll generate a random, inspiring and notable quote or affirmation…
Download (downloaded 542 times) | Plugin Page

Title: Display a Random Quote on your Website
Description: Display a Random Quote on your Website with WordPress Shortcode or PHP.
Download: Shortcode (V0.2) | PHP Code (V0.2) | Plugin Page

Shortt URL for this post: http://shor.tt/1XN6


Please enter your comment!
Please enter your name here