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….
bloginfo
function directly echoes the output. In this case you should useget_bloginfo
to add the returned value to the string and echo the complete string. I believe this will workHere is a better alternative:
I also suggest using the
is_home()
function provided by wordpress to check for the homepage instead of checking the$_SERVER['REQUEST_URI']
value.bloginfo() outputs data with echo and returns nothing, so instead of trying to concatenate everything, just output in sequence, e.g.
Ugly I know, but see answer by Nithesh for a possible alternative.
if you want to get the template path without auto echoing it by the bloginfo() function use: