tags:

views:

26

answers:

2

Not even sure if methods is the correct terminology...

Here is the original working code:

<a href="<?php bloginfo('url'); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title"><?php bloginfo('description'); ?></p>

I wanted it to only execute on the homepage, so I wrote this:

<? 
if ( $_SERVER["REQUEST_URI"] == '/' ){
echo '<a href="'.bloginfo('url').'">
<img src="'.bloginfo('stylesheet_directory').'/images/logo.png" alt="Polished Logo" id="logo"/></a>
<img src="'.bloginfo('stylesheet_directory').'/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title">'.bloginfo('description').'</p>';
}
?>

But it outputs the bloginfo() and the other declarations completely outside the html tags I have created. For instance, with bloginfo('stylesheet_directory') it will display the directory outside the IMG tags I created.

Any ideas? Apparently my syntax isn't correct or something....

+5  A: 

bloginfo function directly echoes the output. In this case you should use get_bloginfo to add the returned value to the string and echo the complete string. I believe this will work

<?php
if ( $_SERVER["REQUEST_URI"] == '/' ) {
  echo '<a href="'.get_bloginfo('url').'">
    <img src="'.get_bloginfo('stylesheet_directory').'/images/logo.png" alt="Polished Logo" id="logo"/></a>
    <img src="'.get_bloginfo('stylesheet_directory').'/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
    <p id="logo_title">'.get_bloginfo('description').'</p>';
}
?>

Here is a better alternative:

<?php if ( $_SERVER["REQUEST_URI"] == '/' ) { ?>
<a href="<?php bloginfo('url') ?>">
  <img src="<?php bloginfo('stylesheet_directory') ?>/images/logo.png" alt="Polished Logo" id="logo"/>
</a>
<img src="<?php bloginfo('stylesheet_directory') ?>/images/separator.png" width="2" height="59" alt="Line" class="logo_line"/>
<p id="logo_title"><?php bloginfo('description') ?></p>
<?php } ?>

I also suggest using the is_home() function provided by wordpress to check for the homepage instead of checking the $_SERVER['REQUEST_URI'] value.

Nithesh Chandra
Thanks so much! Sometime you get stuck in a rut and need someone to show you the right way
Jared
+1  A: 

bloginfo() outputs data with echo and returns nothing, so instead of trying to concatenate everything, just output in sequence, e.g.

echo '<a href="';
bloginfo('url');
echo '"><img src="';
bloginfo('stylesheet_directory');
//etc...

Ugly I know, but see answer by Nithesh for a possible alternative.

Paul Dixon