Site logo

Archived topic

(Random) Rotate Header / Logo (per page view)

15 replies · Started by Genie Bohn on November 22, 2015

Viewing posts 1–15 of 16

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

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.

A rotating background sounds interesting, too - but I was only looking for the header / logo.

Thank you, for your time.

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="" />';
?>

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.

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.

Awesome! Glad I was able to help :)

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?

You're missing the < at the start before the ?.

Thank You.

You're welcome :)

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

Looks like it's missing a comma after the first image link.

I just edited your code so it should work now :)

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 archived topic is closed to new replies.