Title: Changing Header Image Source to Randomize Header Image
Last modified: June 21, 2018

---

# Changing Header Image Source to Randomize Header Image

 *  [webappi](https://wordpress.org/support/users/webappi/)
 * (@webappi)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/changing-header-image-source-to-randomize-header-image/)
 * Hi, I am trying to create a random header image on my homepage, so that the user
   see a different header image on each visit to the homepage. I have set up a folder
   with 5 different images, named them header_1 – header_5 and have written code
   to randomize the image loaded. Here is the code: .jpg” width=”1400″ height=”500″
   alt=”” />. I was wondering where or how I could change the image source so that
   it will use my random images instead.
 * Thank you for your help!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fchanging-header-image-source-to-randomize-header-image%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [webappi](https://wordpress.org/support/users/webappi/)
 * (@webappi)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/changing-header-image-source-to-randomize-header-image/#post-10423584)
 * The code was cut off, here is the code again:
    `<img src="https://con2r.alliedpower.
   com/wp-content/uploads/header/header_<?php echo(rand(1,5)); ?>.jpg" width="1400"
   height="500" alt="Welcome to the Old Skool Zone" />`
 *  Theme Author [satoristudio](https://wordpress.org/support/users/satoristudio/)
 * (@satoristudio)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/changing-header-image-source-to-randomize-header-image/#post-10424310)
 * Hi [@webappi](https://wordpress.org/support/users/webappi/),
 * the header image is set by the `bento_insert_custom_styles()` function in the/
   functions.php theme file. The part you’re looking for is:
 *     ```
       if ( $postheader != '' ) {
       	$custom_css .= '
       		.post-header {
       			background-image: url('.$postheader.');
       		}
       	';
       }
       ```
   
    -  This reply was modified 7 years, 12 months ago by [satoristudio](https://wordpress.org/support/users/satoristudio/).
 *  Thread Starter [webappi](https://wordpress.org/support/users/webappi/)
 * (@webappi)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/changing-header-image-source-to-randomize-header-image/#post-10426039)
 * Awesome, thank you so much! Is there a way to make this change in my child theme/
   functions.php file so it does not overwrite on theme updates?
 * Also, is there a different function that controls the homepage header image set
   in the customizer?
 *  Theme Author [satoristudio](https://wordpress.org/support/users/satoristudio/)
 * (@satoristudio)
 * [7 years, 12 months ago](https://wordpress.org/support/topic/changing-header-image-source-to-randomize-header-image/#post-10432987)
 * You’ll need to add your custom function to the child theme’s functions.php and
   hook it there via the `wp_add_inline_style()` call, similarly to how it’s done
   with the `bento_insert_custom_styles()` in the base theme.
 * The customizer-related styles are set via the `/includes/customizer/customizer.
   php` theme file.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Changing Header Image Source to Randomize Header Image’ is closed to 
new replies.

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

 * 4 replies
 * 2 participants
 * Last reply from: [satoristudio](https://wordpress.org/support/users/satoristudio/)
 * Last activity: [7 years, 12 months ago](https://wordpress.org/support/topic/changing-header-image-source-to-randomize-header-image/#post-10432987)
 * Status: not resolved