Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

change url based on site domain

Hi there. I am running a WordPress Multi-site and need to change the url on a logo on only 1 site. I am using the following but I think I have it wrong:

<?php 
					
					 if (isset($_GET['url']) && $_GET['url'] === 'http://domain.org')
{
echo "<a href="https://otherdomain.org"><?php FLTheme::logo(); ?></a>";
{
	
	else
	
echo "<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php FLTheme::logo(); ?></a>";
		
}
}

?>

Open in new window


Any ideas experts?
ASKER CERTIFIED SOLUTION
Avatar of Thomas Wheeler
Thomas Wheeler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Waller

ASKER

Thomas, how about this line:
if (isset($_GET['url']) && $_GET['url'] === 'http://domain.org')

Open in new window


^ does it make sense?

So I have the following and the site breaks:

<?php 					
if (isset($_GET['url']) && $_GET['url'] === 'http://domain.org') {
echo "<a href=\"https://otherdomain.org\"><?php FLTheme::logo(); ?></a>";
{	
else	
echo "<a href=\"<?php echo esc_url( home_url( '/' ) ); ?>\"><?php FLTheme::logo(); ?></a>";
}
}
?>

Open in new window


What am I doing wrong?
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Ryan Chong. Your solution seemed to work best although the logos don't click through. It's as if there is no link around the logos.

Ray, your code broke the site. Any ideas why?
No, sorry.  I don't have any way to test, so I can't know what is wrong unless you can show me the error message or the log files.  "Broke the site" isn't adequate for debugging.
Ray, the site went blank white. I put your code in here http://phptester.net/ and I see this error:

FATAL ERROR syntax error, unexpected 'https' (T_STRING), expecting ',' or ';' on line number 6
I don't see any parse error, sorry.  I have the script installed here:
https://www.iconoun.com/demo/temp_cowebmaster.php

The output might not be right yet, and might need some adjustment.
Ray, okay I got this to work if I use single quotes:

<?php
error_reporting(E_ALL);

if (isset($_GET['url']) && $_GET['url'] == 'http://domain.org') 
{
	echo "<a href='https://otherdomain.org'>FLTheme::logo()</a>";
}	
else
{
    echo "<a href='esc_url( home_url( '/' ) )'>FLTheme::logo()</a>";
}

Open in new window


However, the line of text FLTheme::logo() appears on the page and not the actual image. Any ideas?
It may be necessary to assign the output of esc_url() and FLTheme::logo() to local variables and put those variables into the anchor tags.
Thanks Ray, I have no idea how to do that. Can you give an example?
Avatar of Thomas Wheeler
Thomas Wheeler

depending on what the function dose you should beable to
$logo_data = FLTheme::logo();

Open in new window


Then you can reference the variable $logo_data instead of the function. Same with
$str_url = esc_url( home_url( '/' ) );

Open in new window

Your solution seemed to work best although the logos don't click through. It's as if there is no link around the logos.
can you tell what's the HTML codes generated from my comment in ID: 41948355 ?
Ryan, the image displays on the page but there is no hyperlink surrounding the image:

<img class="fl-logo-img" itemscope="" itemtype="http://schema.org/ImageObject" src="http://domain.org/path-to-file/logo.png" data-retina="" alt="">