- This topic has 15 replies, 5 voices, and was last updated 4 years, 8 months ago by
Tom.
-
AuthorPosts
-
November 22, 2015 at 12:18 pm #154805
Genie Bohn
I’m still in love with this theme. Running it on 4 or 5 sites.
There is nothing wrong, so if you want to ignore this or come back once you finish the important posts.
I was looking for a plugin, or support code to accomplish rotating the header per landing.
This was one advice that someone gave to another, but I couldn’t seem to get it to work. If you have any thoughts, I would appreciate it.
===========================================================
<style type="text/css"> #header #logo { background: <?php $stylesarray = array("logo1","logo2","logo3"); $random = $stylesarray[rand(0,count($stylesarray)-1)]; echo "url(images/".$random.".gif);" ?> } </style>
===============================================
in your header.php right before this line: <?php wp_head(); ?> that way the new background image will over ride the one in your sttylesheet
November 22, 2015 at 11:09 pm #154876Tom
Lead DeveloperLead DeveloperInteresting idea, but the selector doesn’t match GP.
If you’re trying to set it to the site logo element, you would use:
.site-header .site-logo
However, setting it as a background will require you to set some sort of width and height to the site logo element for it to show up.
You may want to test with the just the
.site-header
element until you know the random functionality is right.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 23, 2015 at 8:03 am #154976Genie Bohn
A rotating background sounds interesting, too – but I was only looking for the header / logo.
Thank you, for your time.
November 23, 2015 at 9:10 am #154994Tom
Lead DeveloperLead DeveloperYou could maybe do something like this in GP Hooks (Before Header Content):
<?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 ) ]; echo '<img src="' . $random . '" alt="" />'; ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 23, 2015 at 9:57 am #154997Genie Bohn
I’ll give this a try, although, I’ve never worked with hooks.
(LATER)
Hooks was snap.
Thank you, Tom
3 – 2 – 1 WE HAVE LIFT-OFF!
(I guess you can figure I live near The Cape)
Most grateful for your time.
November 23, 2015 at 11:15 am #155004Genie Bohn
Just as a follow up….
The site is under re-construction, but you can see the random changes in the header.
Followed your instructions exactly. It will be easy to add more or change the images.
<?php $headers = array( 'http://richardarmitageworld.com/images/logo1.jpg', 'http://richardarmitageworld.com/images/logo2.jpg', 'http://richardarmitageworld.com/images/logo3.jpg', 'http://richardarmitageworld.com/images/logo4.jpg', ); $random = $headers[ rand( 0, count( $headers ) -1 ) ]; echo '<img src="' . $random . '" alt="" />'; ?>
(Click “EXECUTE PHP” underneath.
November 23, 2015 at 1:47 pm #155066Tom
Lead DeveloperLead DeveloperAwesome! Glad I was able to help π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 24, 2016 at 10:07 am #196422Genie Bohn
Something has changed somewhere. I have returned to the random code you mentioned above to put in as a hook which worked at the time. I have latest upgrades of GP and GPP and WP.
The random images works fine, but it is printing out the php code to the screen.
See here Link
Thoughts?
May 24, 2016 at 12:16 pm #196477Tom
Lead DeveloperLead DeveloperYou’re missing the
<
at the start before the?
.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 24, 2016 at 2:07 pm #196500Genie Bohn
Thank You.
-
This reply was modified 6 years, 10 months ago by
Genie Bohn.
May 24, 2016 at 11:46 pm #196558Tom
Lead DeveloperLead DeveloperYou’re welcome π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 28, 2017 at 10:23 am #325225Kim
I’m sure this is a silly error but I can’t find it – I tried this hook but am getting the following error:
Parse error: syntax error, unexpected ‘:’, expecting ‘)’ in /home/suusi515/public_html/2017/wp-content/plugins/gp-premium/hooks/functions/hooks.php(22) : eval()’d code on line 3
Here is the hook
<?php $headers = array( 'https://suusi.org/2017/wp-content/uploads/2017/05/Rainy_Blue_Ridge-Header-1.jpg', 'https://suusi.org/2017/wp-content/uploads/2017/05/chalice_pendants_header.jpg', 'https://suusi.org/2017/wp-content/uploads/2017/05/workshop_fabricart_header.jpg', 'https://suusi.org/2017/wp-content/uploads/2017/05/children_inner_tubes_suusi_header.jpg', 'https://suusi.org/2017/wp-content/uploads/2017/05/WCU_Header.jpg', ); $random = $headers[ rand( 0, count( $headers ) -1 ) ]; echo '<img src="' . $random . '" alt="" />'; ?>
any help is appreciated
May 28, 2017 at 12:01 pm #325254Leo
StaffCustomer SupportLooks like it’s missing a comma after the first image link.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 28, 2017 at 7:06 pm #325373Tom
Lead DeveloperLead DeveloperI just edited your code so it should work now π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 11, 2018 at 3:28 pm #621512William
I’d like to do this and tried the code and it “sort of” worked for me.
I know nothing about php and I’m a WP newbie. I found the header.php file and inserted the code just before the line: “<?php wp_head(); ?>”
The the desired, randomized image were displayed on the site but they were above and to the left of the usual logo image. The usual logo image was still in place.
Can you help?
Thanks!
-
This reply was modified 6 years, 10 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.