Random background on wordpress.com hosted blog

219 views Asked by At

I wonder if it's possible to add a random background for a blog hosted on wordpress.com. Every time the visitor enter the page or press F5, a different background should load. How can I do that?

2

There are 2 answers

2
maiorano84 On

Yes. It is possible to load random backgrounds each time the user loads or refreshes the page.

UPDATE: Based on your update to your question, it seems that you now want to know HOW to do this rather than just if it's possible. A very simple way would be something like this:

<?php
$directory = ABSPATH."wp-content/themes/your_theme_name/images/backgrounds/";
$images = glob($directory."*.jpg");
$randBG = str_replace(ABSPATH, site_url('/'), array_rand($images));
?>
<body style="background:#FFF url(<?php echo $randBG; ?>) no-repeat center 0 scroll">

What this would do is scan a directory named "backgrounds" that sits in your images folder in your theme's directory. A random jpeg from that folder would be chosen, and your body element would be styled accordingly.

0
Jojo Avav On

Actually, it is not possible to achieve this effect on a Wordpress.com site (unless the theme grants it). Wordpress.org allows you to install plugins, and edit the individual files, but Wordpress.com is extremely limited.