Skip to content
GeneratePress
  • Home
  • Premium
  • Site Library
  • Install
  • Help
    • Documentation
    • Support Forum
    • Contact
  • Log In
GeneratePress
  • Home
  • Premium
  • Site Library
  • Install
  • Help
    • Documentation
    • Support Forum
    • Contact
  • Log In
  • Log In
  • Free Support

[Resolved] (Random) Rotate Header / Logo (per page view)

Home › Forums › Support › (Random) Rotate Header / Logo (per page view)

  • This topic has 15 replies, 5 voices, and was last updated 2 years, 7 months ago by Tom.
Viewing 15 posts - 1 through 15 (of 16 total)
1 2 →
  • Author
    Posts
  • 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 #154876
    Tom
    Lead Developer
    Lead Developer

    Interesting 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-development

    November 23, 2015 at 8:03 am #154976
    Genie 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 #154994
    Tom
    Lead Developer
    Lead Developer

    You 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-development

    November 23, 2015 at 9:57 am #154997
    Genie 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 #155004
    Genie 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.

    RichardArmitageWorld

    <?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 #155066
    Tom
    Lead Developer
    Lead Developer

    Awesome! 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-development

    May 24, 2016 at 10:07 am #196422
    Genie 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 #196477
    Tom
    Lead Developer
    Lead Developer

    You’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-development

    May 24, 2016 at 2:07 pm #196500
    Genie Bohn

    Thank You.

    • This reply was modified 4 years, 9 months ago by Genie Bohn.
    May 24, 2016 at 11:46 pm #196558
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    Documentation: http://docs.generatepress.com/
    Adding CSS: http://docs.generatepress.com/article/adding-css/
    Ongoing Development: https://generatepress.com/ongoing-development

    May 28, 2017 at 10:23 am #325225
    Kim

    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 #325254
    Leo
    Staff
    Customer Support

    Looks 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 #325373
    Tom
    Lead Developer
    Lead Developer

    I 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-development

    July 11, 2018 at 3:28 pm #621512
    William

    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!

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 16 total)
1 2 →
  • You must be logged in to reply to this topic.
Log In

Common Issues

  • Missing style.css
  • Updating errors
  • Plugin Install Failed

Useful Articles

  • Installing GP Premium
  • Installing GeneratePress
  • How to add CSS
  • How to add PHP

GeneratePress

  • About
  • Premium
  • Site Library
  • Gutenberg
  • Affiliates
  • Reviews
  • Brand Assets
  • Blog
  • We’re Hiring!

Support

  • Documentation
  • Contact Us
  • Support Forums
  • Fastest WordPress Theme
  • Changelogs
  • Legal
  • Donate
  • Translate

Popular FAQs

  • Install GeneratePress
  • Installing GP Premium
  • Missing style.css
  • Plugin Install Failed
  • Adding CSS
  • Adding PHP
  • WordPress Hosting

Social

  • Facebook
  • Twitter
  • WordPress
  • GitHub
Made with on Vancouver Island
  • Home
  • Premium
  • Site Library
  • Install
  • Contact
  • Support Forum
  • Documentation
  • Account
  • Checkout