Jump to content

IF page == home, then...


MSUK1

Recommended Posts

Hello,

 

i am wanting to show a logo on the home page, and on any other page, a completly different logo..

 

I was thinking about using what i know from shtml, but my site is in php?

 

i was thinking it would be like..

 

if url == www.domain.com, then -> logo 1, else if !== www.domain.com then -> logo2?

 

can anyone help me out wiht this?

 

thanks,

Link to comment
Share on other sites

<?php
$server_page = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
//echo $server_page."<br />";
$current_page = end(explode("/", $server_page));
if($current_page == "index.php") {
$logo = "./images/logo1.png";//use your logo location
} else {
$logo = "./images/logo2.png";
}
?>

Link to comment
Share on other sites

Yes i can see how that is possible.

 

This will find home within each folder, meaning per script path or could very well be a subdomain path

<?php
//get the url from the address bar
$current_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$current_url .= "?".$query_string;
}
//explode url into parts by /,get the last part
$current_file_path = end(explode("/", $current_url));
echo $current_url."<br />";
echo $current_file_path."<br />";

if(empty($_SERVER["QUERY_STRING"]) && $current_file_path == "index.php"){
echo "HOME";
} else {
echo "NOT HOME";
}
?>

 

Otherwise, this may just work for you

<?php
//get the url from the address bar
$current_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$current_url .= "?".$query_string;
}

$home_url = filter_var("http://".$_SERVER['HTTP_HOST']."/", FILTER_SANITIZE_STRING);
$index_url = filter_var("http://".$_SERVER['HTTP_HOST']."/index.php", FILTER_SANITIZE_STRING);
if($current_url == $home_url || $current_url == $index_url){
$is_home = true;
}

if(empty($_SERVER["QUERY_STRING"]) && $is_home == true){
$logo = "./images/logo1.png";//use your logo location
} else {
$logo = "./images/logo2.png";
}
?>

 

Link to comment
Share on other sites

Here's an example of how I made different images for the site names link in the default twentyeleven theme.

 

I placed 2 images in the themes images folder, gave full url of the image.

The new php area with check for is_home and is_front_page just after </head>

For the sites link had to add <?php echo $custom_image;?>

</head>
<?php
//php block added
if (is_home() || is_front_page() ){
$custom_image ="<img src='http://localhost/wp-content/themes/twentyeleven/images/headers/logo.png'/>";
} else {
$custom_image ="<img src='http://localhost/wp-content/themes/twentyeleven/images/headers/banner.jpg'/>";
}
?>
<body <?php body_class(); ?>>
<div id="page" class="hfeed">
<header id="branding" role="banner">
		<hgroup>
			<h1 id="site-title"><span><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php echo $custom_image;//this instead of sites name ?></a></span></h1>
			<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
		</hgroup>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.