2

The agency I work for are trying to get a client's logo to change based upon the incoming URL.

Now, we have 4 different URLs, therefore 4 different logos.

Currently, we are using an if/else statement, though we keep getting the alt text as opposed to the image. The image source is definitely correct.

if(!empty($image)) {
     echo '<h1>WEBSITE_NAME_HERE</h1>';
 } else {
    echo '<img src="'.logoSwap().'" alt="Localised Logo">';
}

For the function that has been declared (logoSwap()), we are using this code in the functions.php file:

<?php
function logoSwap(){
switch($_SERVER['HTTP_HOST']) {
    case 'WEBSITE_URL_HERE.com': 
        $logo = "WEBSITE_URL_HERE/wp-content/uploads/2016/01/logo-red.png";
    break;
    case 'www.WEBSITE_URL_HERE.com':
        $logo = "WEBSITE_URL_HERE/wp-content/uploads/2016/01/logo-red.png";
    break;
    case 'WEBSITE_URL_HERE.co.uk':
        $logo = "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png";
    break;
    case 'www.WEBSITE_URL_HERE.co.uk':
        $logo = "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png";
    break;
    default:
        $logo = "WEBSITE_URL_HERE/wp-content/uploads/2015/09/logo.png";
    break;
};}
?>

The trouble is, only the alt tag is feeding through.

Localised Logo Alt Tag

Is there somewhere specific I should be putting the second PHP script? Am I not calling to the logo correctly?

We are using a Themify theme, so I am not sure whether that will throw a spanner into the works.

Any help is much appreciated.

7
  • 1
    This looks like a pure PHP problem as you present it. ps: you're missing the return $logo; part in the logoSwap() function.
    – birgire
    Jan 7 '16 at 9:56
  • @birgire Okay, I now feel rather silly because the return $logo; got the logo to start displaying. However, I'm still having the problem that it won't change logo based upon the incoming domian. The .com domain is currently set up as a 502 redirect to the .co.uk domain - could that be the issue? Jan 7 '16 at 10:04
  • 1
    don't be, that kind of code-blindness has and will happen to us all ;-) You mean a 30x redirect (502 usually stands for a bad gateway) ?
    – birgire
    Jan 7 '16 at 10:08
  • Yes I mean a 301. I did a quick google and must have misread it. It is using a 301 redirect which is pulling it directly to the .co.uk domain, however the logo isn't changing when accessed from the .com domain. Could it simply be the fact that it is coming in via a 301 redirect? For example, I will type in mywebsite.com and I will get redirected to mywebsite.co.uk, however it displays the same logo. Jan 7 '16 at 10:35
  • You should create e.g. a pure HTML file where you try to display all the logos, just to make sure they display correctly, before it's all wrapped within a PHP code. I'm afraid I will have to vote to close the question as it's not related to WordPress and therefore off-topic according to the site's rule. Best of luck with the project.
    – birgire
    Jan 7 '16 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.