Sebastian
Sebastian

Reputation: 83

What' wrong with this syntax?

I am sure this is simple, but I don't get why... Why is this wrong?

echo "<img src='".bloginfo('template_directory')."/systemdata/next.png' border=0 id='NavImage'>";

If I do it like this, it works:

echo "<img src='";
echo bloginfo('template_directory');
echo "/systemdata/next.png' border=0 id='NavImage'>";

What do I do not get? I want to write nice code and the second example is not very elegant I think.

Thanks!

Upvotes: 1

Views: 55

Answers (2)

Gagan Deep
Gagan Deep

Reputation: 489

You can try this as far as code elegant factor is concerned:

$blogingo=bloginfo('template_directory');
echo "<img src=$blogInfo/systemdata/next.png' border=0 id='NavImage'>";

Upvotes: 0

jeroen
jeroen

Reputation: 91734

You are using the wrong function, bloginfo() already outputs / echoes so you cannot use it when you want to concatenate strings (nor should you echo it...).

Instead you could use get_bloginfo() as that returns a string:

echo "<img src='".get_bloginfo('template_directory')."/systemdata/next.png' border=0 id='NavImage'>";

Upvotes: 2

Related Questions