- This topic has 15 replies, 5 voices, and was last updated 5 years, 8 months ago by Tom.
-
AuthorPosts
-
November 22, 2015 at 12:18 pm #154805Genie 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 #154876TomLead 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.November 23, 2015 at 8:03 am #154976Genie BohnA 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 #154994TomLead 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="" />'; ?>
November 23, 2015 at 9:57 am #154997Genie BohnI’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 BohnJust 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 #155066TomLead DeveloperLead DeveloperAwesome! Glad I was able to help π
May 24, 2016 at 10:07 am #196422Genie BohnSomething 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 #196477TomLead DeveloperLead DeveloperYou’re missing the
<
at the start before the?
.May 24, 2016 at 2:07 pm #196500Genie BohnThank You.
- This reply was modified 7 years, 10 months ago by Genie Bohn.
May 24, 2016 at 11:46 pm #196558TomLead DeveloperLead DeveloperYou’re welcome π
May 28, 2017 at 10:23 am #325225KimI’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 #325254LeoStaffCustomer SupportLooks like it’s missing a comma after the first image link.
May 28, 2017 at 7:06 pm #325373TomLead DeveloperLead DeveloperI just edited your code so it should work now π
July 11, 2018 at 3:28 pm #621512WilliamI’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!
-
AuthorPosts
- You must be logged in to reply to this topic.