If you like to get more page views per visitor on your WordPress site or blog you should try a random post button. People like to get surprised on what the next page will show them. The whole idea of StumbleUpon is based on random web pages, every time you click their stumble button you get a new random article, image or video.

The following code will select a random article and shows the link together with a graphical button on your site.

If you “echo” the function somewhere in your theme, a random post link will show up with your button. Note the number “1000” used inside the function “wp_get_attachment_url()”, this is the ID from the image used as your button.

Create a WordPress shortcode

A much better concept would be by using a shortcode in your article, theme or widget. Use this code to create a shortcode instead:

Now you can use this shortcode in your article or post:

[randPost image="1000" alt="Random post"]

If you like to use this short code inside the text widget you need to add this filter into your functions.php file too:

I used the same code in the sidebar for each article on my Web Development Blog. Tip! Experiment with different positions, button text and colors and if you like share your results here.