WordPress Random Background


/ Published in: PHP
Save to your folder(s)

Do not forget to name images you want to use for background like 1.jpg, 2.jpg, 3.jpg etc.


Copy this code and paste it in your HTML
  1. html,
  2. body { height: 100%; }
  3.  
  4. img#bg {
  5. position:fixed;
  6. top:0;
  7. left:0;
  8. width:100%;
  9. height:100%;
  10. }
  11.  
  12. <body>
  13.  
  14.  
  15. <?php $random_image = rand(1, 5); /*let's choose random image...*/ ?>
  16. <img id="bg" alt="" src="<?php bloginfo('stylesheet_directory');?>/images/<?php echo $random_image; ?>.jpg" />

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.