I'm Andreas Kambanis and I'm the founder of Nibble Apps. This blog is all about creating and launching successful apps.

Menu & Search

PHP random content on wordpress

I wanted to split test my post footer in WordPress so I could try out two different Aweber forms. However the forms didn’t display in the way I wanted.

The code I ended up using:

$chosen = mt_rand(1,3);
case 1:
include ‘first.php’;
case 2:
include ‘second.php’;
case 3:
include ‘third.php’;
echo ‘something went horribly wrong’;

From: Random HTML snippets with PHP include?

This worked very well for me. I simply removed case 3 and changed mt_rand(1,3); to mt_rand(1,2);

This then randomly chose between my first block of text and my second block of text. This meant I could split test their effectiveness by embedding two different aweber forms. When the first form is randomly loaded it counts it in Aweber and then when the second form randomly loads again the results are counted. This meant I could customise the text in a way I wanted and not have to use Awebers built in e-mail forms which were not effective and looked ugly.

Hope this helps someone looking to randomise the way content appears on a page.

Article Tags
Related article

Wp_footer WordPress hack hidden links

Running a huge cycling blog and gaining a good reputation…

Best desktop blog editor

If you are using Windows then the best Desktop Blog…

How to link cloak in WordPress

As a blogger with over 50,000 visitors every month I…

Discussion about this post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Type your search keyword, and press enter to search