Peekaboo Randomizer

Peekaboo Randomizer

Peekaboo Randomizer is a plugin that allows you to randomly display pieces of content at your Wordpress-driven website. It’s suitable for banner rotation, lucky visitor rewards, special offers… or just for making a webpage more exciting and fun.
Unlike some other similar plugins, Peekaboo Randomizer requires no JavaScript at the front end, and does all the job at the server.
You can play with it (and with Peekaboo Timer) in the Demo, located here.

Upon installing the plugin, you will be in the possesion of 3 shortcodes with which you can choose which block of content you want to be randomly displayed to visitors, and with what incidence.

Installation simple. As with pretty much any other WP plugin, you should:

  • 1. unzip the package
  • 2. upload the entire peekaboo_randomizer folder to your plugins directory
  • 3. activate the plugin in Wordpress dashboard (Plugins page)
A new icon in the Wordpress’ TinyMCE text editor toolbar is created:



attribute: chance

The most basic usage. This shortcode is used when you have a block of content that should appear on the page randomly, unrelated to what happens with the rest of the content.


[pbr_single chance=”25%”]This sentence will appear on the page in 25% of the cases, or once in 4 loadings, in average.[/pbr_single]
[pbr_single chance=”3/8”]This sentence will appear on the page three times in eight calls.[/pbr_single]
[pbr_single chance=”0.01%”]The incidence of 0.01% means the content will appear on the page once in 10000 times.[/pbr_single]
[pbr_single chance=”1/10000”]Same as the above.[/pbr_single]

As shown in the previous examples, the attribute chance can be expressed both as percentage or as fraction. Percentage value can have up to 6 decimals; which also means the lowest frequency of appearance is 0.000001%, or 1/1000000.
Note: if you’re using fractions, do not attempt to divide them yourself. For example, do write 1/4, not 0.25. When you write 0.25 Randomizer will assume you meant 0.25%, as ’%’ sign is not mandatory in the value of chance attribute.

Wordpress doesn’t support nesting of a shortcode inside itself.

[shortcode]Whatever [shortcode] this shortcode is supposed to do [/shortcode]- it will not do properly.[/shortcode]

But, understanding that you may have a need to randomly display some content inside a larger randomly displayed block, Peekaboo Randomizer allows you to do so. Just add a number suffix to the shortcode name:

[pbr_single chance=”1/3”]The larger block appears once in three loadings [pbr_single2 chance=”50%”], while this inner block appears in 50% of those cases.[/pbr_single2] Which means the inner block will be present on the page in 1/6 cases in total.[/pbr_single]

You can nest these shortcodes up to 10 levels deep; from [pbr_single2] to [pbr_single10]. Just be careful to properly close each shortcode.


no attributes


attributes: set and chance

You can have several alternative blocks of content, while only one of them gets to be displayed on the page. For these cases you can create Peekaboo Randomizer sets.
In order for a [pbr] shortcode block to “know” if another block from the same set is randomly chosen this time, not him, we need to feed all blocks to PB Randomizer, which will then do the wiring between them.
For that purpose use [pbr_wrapper] shortcode, to nest all [pbr] shortcodes inside.
The easiest, but also the most reliable way to do so is to start writing the content of a page by placing [pbr_wrapper] first, before everything else in the WP text editor, and [/pbr_wrapper] last. The entire page content can be safely nested inside the wrapper.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
[pbr set=”owls” chance=”25%”]<img src="snowy.jpg" />[/pbr]
[pbr set=”owls” chance=”50%”]<img src="”scops.jpg"" />[/pbr]
[pbr set=”owls” chance=”1/10”]<img src="barn_owl.jpg" />[/pbr]
[pbr set=”owls” chance=”15%”]<img src="strix.jpg" />[/pbr]
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
There are four alternating blocks that belong to the set named “owls” in this example. Each block contains an image of an owl. Snowy owl will appear 25% of the time, scops owl 50%, strix owl – 15%, while the image of barn owl will load once in ten cases. Only one image loads each time.

IMPORTANT: The sum of all chances in one set has to be exactly 100% (i.e. 1/1) in order for the randomizer set to work properly.

You can have as many sets inside one pbr_wrapper as you wish.
Mind you, instances of a set do not have to reside next to each other.

Another example:
[pbr set=”cats” chance=”50%”]Maine Coon[/pbr]
[pbr set=”dogs” chance=”40%”]German Shepherd[/pbr]
Siberian Husky
[pbr set=”dogs” chance=”25%”]Labrador Retriever[/pbr]
Border Collie
[pbr set=”cats” chance=”50%”]Russian Blue[/pbr]
Scottish Fold
[pbr set=”dogs” chance=”35%”]Dalmatian[/pbr]

Nesting of [pbr] shortcodes is also possible, but in a bit different way than [pbr_single] is, and only one level down.

If an item/instance/block of a set is nested inside an item/instance/block of another set, it is necessary to use [pbr2] shortcode for defining the inner block and all other blocks which belong to the set (regardless whether those blocks are also nested or not).

Also, there have to be two wrappers. A standard [pbr_wrapper], and [pbr_wrapper2]. As is the case with a single wrapper – the best and cleanest way is to open them both at the beginning, and close them at the very end of the content.

Take a careful look at this example:
[pbr set=”living creatures” chance=”5/13”]
  [pbr2 set=”animals” chance=”20%”]Koala[/pbr2]
  [pbr2 set=”animals” chance=”20%”]Wolf[/pbr2]
  [pbr2 set=”animals” chance=”20%”]Fox[/pbr2]
  [pbr2 set=”insects” chance=”50%”]Wasp[/pbr2]
  [pbr2 set=”insects” chance=”50%”]Mosquito[/pbr2]
[pbr2 set=”animals” chance=”40%”]Penguin[/pbr2]
[pbr set=”people” chance=”28%”]Harry[/pbr]
[pbr set=”living creatures” chance=”8/13”]
  [pbr2 set=”trees” chance=”61%”]Cypress[/pbr2]
  [pbr2 set=”trees” chance=”39%”]Chestnut[/pbr2]
[pbr set=”people” chance=”36%”]Jane[/pbr]
[pbr set=”people” chance=”36%”]John[/pbr]

Note that the “penguin” block of “animals” set is also wrapped in [pbr2], even it is not inside “living creatures” set. Since there’s at least one block of “animals” set nested inside “living creatures” then all other items from the “animals” have to have the sub-shortcode [pbr2].
No item of the set “people” is nested, so it’s just a regular [pbr] set.


As mentioned at the beginning, there’s a convenient click-through dialog available in the Wordpress’ text editor, which should make inserting shortcodes a breeze.

Bear in mind that the laws of probability sometimes may seem counter-intuitive and illogic. If you have set some content to appear on a page with a frequence of, say, 50%, don’t be alarmed if sometimes the content appears 5 times in a row… or if 7 times in a row it doesn’t… It may happen more often than you’d maybe expect.
So, if you suspect that something is wrong with the mechanism of randomizing inside the plugin, please test it thoroughly by reloading the page multiple (really multiple) times and taking notes of the (dis)appearance pattern. Probability is all about the Law of Large Numbers

Finally, let me inform you about the existance of Peekaboo Timer plugin, that you may find useful for combining with Randomizer.
Peekaboo Timer hides or shows any content in accordance with various time-related criteria. For example, you can make some blocks of content appear randomly (if combined with Randomizer) on a page during working hours, while other blocks shall appear on weekends and off-hours, etc…
Take a closer look: