- This topic has 16 replies, 5 voices, and was last updated 8 years, 5 months ago by
Tom.
-
AuthorPosts
-
February 29, 2016 at 11:04 am #176129
w8krf
When I was using another theme before I found yours, which is much better, in my opinion, I was able to have several header background images which would randomly change when a new page was accessed. I only see the capability to have one image in your theme. Would it be possible to do what I want in GeneratePress? I have purchased the add-on package and am having a ball customizing but I do not see any way of having multiple header images.
Thanks.
Carl Rimmer
http://www.w8krf.netFebruary 29, 2016 at 10:00 pm #176194Tom
Lead DeveloperLead DeveloperHi there,
This topic might be helpful: https://generatepress.com/forums/topic/random-rotate-header-logo-per-page-view/
That will work with actual images in the header though. If you want to use background images, you could do something like this in the wp_head hook in “Appearance > GP Hooks”:
<?php $headers = array( 'http://yourwebsite.com/URL/TO/header1.jpg', 'http://yourwebsite.com/URL/TO/header2.jpg', 'http://yourwebsite.com/URL/TO/header3.jpg', 'http://yourwebsite.com/URL/TO/header4.jpg', ); $random = $headers[ rand( 0, count( $headers ) -1 ) ]; ?> <style> .site-header{background-image:url('<?php echo $random; ?>');} </style>Be sure to check “Execute PHP” 🙂
March 1, 2016 at 3:44 pm #176470w8krf
That worked. Excellent. Thank you.
March 1, 2016 at 9:54 pm #176513Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
March 17, 2017 at 5:00 pm #293650Mo
Hi Tom,
How would that script you provided in the solution provided in Reply 176194 for rotating header images be adapted to random generated page backgrounds?I’ve used the GP Hooks before but as usual the PHP confounds me.
I’m assuming that $headers would need to be replaced with something.
.site-header would be replaced by “body”?
Haven’t used GP for a while and had some pleasant surprises activating it for my latest build.
Thank you.
MoMarch 17, 2017 at 5:50 pm #293661Mo
Hye Tom,
Disregard my last request as I think the coding modification has been solved.
If there are any unforseen issues I’ll start a new post.
Thanks,
MoMarch 17, 2017 at 6:59 pm #293685Tom
Lead DeveloperLead DeveloperGlad you got it sorted 🙂
March 18, 2017 at 1:35 am #293746Joseph
Hello, That script works wonders but it also shows on my main page which has a video header. the video overwrites it but it looks messy.
I used this css to style it out but to no avail.
.page-id-17 .site-header {background-image:display:none!important;}Here is what I am talking about.
http://www.freedomfactor.org/staging/Thanks in advance!!
March 18, 2017 at 9:32 am #293897Tom
Lead DeveloperLead DeveloperWhat about it looks messy? While it’s loading?
March 18, 2017 at 10:31 am #293932Joseph
While loading on the main page, it shows the backgrounds I’ve added to the script then quickly changes to the video. Each time the main page is loaded it will show the scripted background then change to the video. It was mentioned to us from our client and I was just wanting to stop the display of the script on that particular page (main page) by using either css or gphooks (display:none)
All the other pages work great.Thanks,
March 18, 2017 at 8:44 pm #294123Tom
Lead DeveloperLead DeveloperYou could try this:
.home .site-header { background-image: none; }March 19, 2017 at 4:58 am #294227Joseph
Thank you sir, that did the trick. Much appreciated!!
March 19, 2017 at 10:08 am #294327Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
May 18, 2017 at 12:47 am #319689Talya
HEY,
Sorry for barging into this discussion – I’ve tried the random background images, did it yesterday and worked like a charm. Wanted to add another image and since then can’t make it to work again, this is my code:<link href="https://fonts.googleapis.com/css?family=Alef|Heebo|Secular+One|Suez+One" rel="stylesheet"> <?php $headers = array( 'http://chubeza.com/newsletter/wp-content/uploads/2009/12/header_lettuce.jpg', 'http://chubeza.com/newsletter/wp-content/uploads/2009/12/field.jpg', 'http://chubeza.com/newsletter/wp-content/uploads/2006/04/corn.jpg', 'http://chubeza.com/newsletter/wp-content/uploads/2010/07/red.jpg', 'http://chubeza.com/newsletter/wp-content/uploads/2009/12/rainbow.jpg’, 'http://chubeza.com/newsletter/wp-content/uploads/2009/12/header_04.jpg', ); $random = $headers[ rand( 0, count( $headers ) -1 ) ]; ?> <style> .site-header{background-image:url('<?php echo $random; ?>');} </style>What am I doing wrong?
the website is http://chubeza.com/
Thanks!May 18, 2017 at 12:49 am #319693Tom
Lead DeveloperLead DeveloperLooks like you have a “curly” quote after rainbow.jpg – try replacing that with a straight quote like the others.
-
AuthorPosts
- You must be logged in to reply to this topic.