Php code for WordPress

I am doing a WordPress theme that uses a php random image file. I want to know how to adapt this code to WordPress so I can use the bloginfo for the paths to the url and image folder instead of hard coding them in.
I am currently using

<?php
$img_rand = array(
   1 => array(
        'img' => 'image5.jpg', // Add file name, type, even path if needed
		'wth' => '751',        // Width if not a fixed variable
        'hgt' => '109',        // Height if not a fixed variable
		'alt' => 'ISC logo'  // Alt text... IF needed (consider this) 
),                              
   2 => array(
        'img' => 'image9.jpg',
		'wth' => '751',        // Width if not a fixed variable
        'hgt' => '109',        // Height if not a fixed variable
		'alt' => 'ISC logo'  // Alt text... IF needed (consider this) 
),
   3 => array(
        'img' => 'image11.jpg',
		'wth' => '751',        // Width if not a fixed variable
        'hgt' => '109',        // Height if not a fixed variable
		'alt' => 'ISC logo'  // Alt text... IF needed (consider this) 
),
);
?>
<?php
$img = array_rand($img_rand);
echo('   <a href="http://localhost/attorney/"><img src="http://localhost/attorney/wp-content/themes/attorney/images/headers/'.$img_rand[$img]['img'].'" width="'.$img_rand[$img]['wth'].'" height="'.$img_rand[$img]['hgt'].'" alt="'.$img_rand[$img]['alt'].'" /></a>

');
?>

But I would like it to use

<?php
$img_rand = array(
   1 => array(
        'img' => 'image5.jpg', // Add file name, type, even path if needed
		'wth' => '751',        // Width if not a fixed variable
        'hgt' => '109',        // Height if not a fixed variable
		'alt' => 'ISC logo'  // Alt text... IF needed (consider this) 
),                              
   2 => array(
        'img' => 'image9.jpg',
		'wth' => '751',        // Width if not a fixed variable
        'hgt' => '109',        // Height if not a fixed variable
		'alt' => 'ISC logo'  // Alt text... IF needed (consider this) 
),
   3 => array(
        'img' => 'image11.jpg',
		'wth' => '751',        // Width if not a fixed variable
        'hgt' => '109',        // Height if not a fixed variable
		'alt' => 'ISC logo'  // Alt text... IF needed (consider this) 
),
);
?>
<?php
$img = array_rand($img_rand);
echo('   <a href="<?php bloginfo('url'); ?>"><img src="<?php bloginfo('template_url'); ?>/images/headers/'.$img_rand[$img]['img'].'" width="'.$img_rand[$img]['wth'].'" height="'.$img_rand[$img]['hgt'].'" alt="'.$img_rand[$img]['alt'].'" /></a>

');
?>

This doesn’t work. Is there another way to write it so it works with WordPress?

Try


echo '   <a href="'.bloginfo('url').'"><img src="'.bloginfo('template_url').'/images/headers/'.$img_rand[$img]['img'].'" width="'.$img_rand[$img]['wth'].'" height="'.$img_rand[$img]['hgt'].'" alt="'.$img_rand[$img]['alt'].'" /></a>';

The way you had it, it wasn’t calling the bloginfo function.

This is what your code outputs

<p class="logo">http://localhost/attorneyhttp://localhost/attorney/wp-content/themes/attorney   <a href=""><img src="/images/headers/image5.jpg" width="751" height="109" alt="ISC logo" /></a></p>