Title: Using a php script for a randomized image
Last modified: November 13, 2017

---

# Using a php script for a randomized image

 *  [blackscans](https://wordpress.org/support/users/blackscans/)
 * (@blackscans)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/using-a-php-script-for-a-randomized-image/)
 * Hello!
 * I am currently trying to use a random background image inside the ‘site-branding’
   container and even though I’m pretty sure that my script itself works, the ‘GetElementbyID”
   command doesn’t seem to do anything – no matter where I put it. I read somehwere
   that it should appear after the class that you want to use it with, but even 
   putting the script at the end of the ‘body’ section didn’t make it work. Is there
   anything that I have to consider with this theme? Is there something preventing
   it from working?
 * The script:
    <div id=”site-branding”></div> <script type=”text/javascript”> var
   imgCount = 2; var dir = ‘[http://8lackscans.de/wp-content/banner/&#8217](http://8lackscans.de/wp-content/banner/&#8217);;
   var randomCount = Math.round(Math.random() * (imgCount – 1)) + 1; var images 
   = new Array images[1] = “Banner01.png”, images[2] = “Banner02.png”; document.
   getElementById(“site-branding”).style.backgroundimage = “url(” + dir + images[
   randomCount] + “)”; </script>
 * (I used an ‘alert’ line after that to make sure that the link is correct and 
   that it’s random every time you reload the page.. and that works as intended.)
 * I am using a CustomCSS PlugIn that is part of the SiteOrigin Pagebuilder to change
   up a few things (I COULD use the CustomCSS of the theme but it’s actually less
   convenient to do so). I have a couple of lines in there that change a few things
   with the site-branding container, like this:
    background-repeat: no-repeat; background-
   position: center; margin-top: 20px; height: 225px;
 * I already tried changing the position of the script from header.php to footer.
   php and I also got rid of the customCSS COMPLETELY.. nothing worked. I can post
   the complete sourcecode if that’d help.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fusing-a-php-script-for-a-randomized-image%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

The topic ‘Using a php script for a randomized image’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/awaken/2.3.1/screenshot.png)
 * Awaken
 * [Support Threads](https://wordpress.org/support/theme/awaken/)
 * [Active Topics](https://wordpress.org/support/theme/awaken/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/awaken/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/awaken/reviews/)

## Tags

 * [awaken theme](https://wordpress.org/support/topic-tag/awaken-theme/)
 * [banner](https://wordpress.org/support/topic-tag/banner/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [site branding](https://wordpress.org/support/topic-tag/site-branding/)

 * 0 replies
 * 1 participant
 * Last reply from: [blackscans](https://wordpress.org/support/users/blackscans/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/using-a-php-script-for-a-randomized-image/)
 * Status: not resolved