PHP noob needs help

Calamity

New member
Jun 12, 2009
291
7
0
Yurop
After a lot of trial and error i finally got this code to work in a Wordpress footer:
Code:
{
    echo "© ".date("Y");
       echo "  ";
       echo '<a href="';
       echo bloginfo('url');
       echo '">';
       echo bloginfo('name');
       echo '</a>';
}
Is there any way to write this in one echo statement or shorten it down? It works as it is but I just wonder if it is possible to make it smaller?
 


this should work

echo "© ".date("Y")." <a href=\"".bloginfo('url')."\">".bloginfo('name')."</a>";

the dot is the concatenation operator for strings in PHP, so instead of a list of echo statements you can put dots between the strings you want to concatenate.
 
Thanks for the dot thingy Icecube, but the shortest I can get it functional is:
{
echo "© ".date("Y")."  ".'<a href="';
echo bloginfo('url').'">';
echo bloginfo('name').'</a>';
}
For some reason those bloginfo functions dont want to play nice.
 
I can't test it now, anyway pay attention to quotes, single and double quotes work totally different. Also, don't omit the \ before " because that's what makes the script print the "
" is a special char in php so you need to "escape" it preceeding it with a \ when you want your script to print it.

to make it easy you should be able to use always " instead of ' in this piece of php, try replacing all the 's with "
 
For some reason those bloginfo functions dont want to play nice.

That's because bloginfo() prints out the value, you don't need to "echo" it.

If you just want the value, use get_bloginfo().

Function Reference/bloginfo « WordPress Codex
Function Reference/get bloginfo « WordPress Codex

So, either use something like

Code:
© <?php echo date("Y"); ?> <a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a>

or

Code:
© <?php 

echo date('Y'),
     ' <a href="',
     get_bloginfo('url'),
     '">',
     get_bloginfo('name');

?></a>
 
a single line would be:
Code:
© <?php echo date('Y')."<a href=\".get_bloginfo('url')."\">".get_bloginfo('name') ;?></a>

Rob