• 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 to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter webappi

    (@webappi)

    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

    (@satoristudio)

    Hi @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 6 years, 5 months ago by satoristudio.
    Thread Starter webappi

    (@webappi)

    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

    (@satoristudio)

    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.