Monday, 15 April 2013

wordpress - PHP Variable not displaying image that uses bloginfo('template_directory') -



wordpress - PHP Variable not displaying image that uses bloginfo('template_directory') -

i need store hyperlinked image within variable, , echo out variable wordpress website. find more convenient utilize bloginfo('template_directory') can go , forth between local , live server.

but bloginfo('template_directory') within variable not work, displays nothing. bloginfo('template_directory') work in other areas of website. problem?

code works. notice 127.0.0.1 in url

<?php $var = '<a href="http://www.twitter.com"> <img src="http://127.0.0.1/wp-content/themes/twentyfourteen/images/social/twitter.png" /> </a>'; echo $var; ?>

code b displays nothing. why below not working? notice below using bloginfo('template_directory') instead of 127.0.0.1

<?php $var = '<a href="http://www.twitter.com"> <img src="<?php bloginfo('template_directory'); ?>/images/social/twitter.png" /> </a>'; echo $var; ?>

edit

code c how replace word "twitter" variable? (i referring line 3 below, word "twitter" located in img src)

<?php $var = '<a href="http://www.website.com"> <img src="' . get_bloginfo("template_directory") . '/images/social/twitter.png" /> </a>'; echo $var; ?>

you need utilize get_bloginfo want in var. no need php tags when in string. http://codex.wordpress.org/function_reference/get_bloginfo

<?php $var = '<a href="http://www.twitter.com"><img src="'. get_bloginfo('template_directory') .'/images/social/twitter.png" /></a>'; echo $var; ?>

also suggest using instead kid themes. http://codex.wordpress.org/function_reference/get_template_directory_uri

<?php $var = '<img class="svg " src="'. get_template_directory_uri() .'/images/social/twitter.png">' echo $var; ?>

in response edit c code block, i'm guessing trying loop through social media icon links. how might that:

<?php // array of social sites $sites = array( 'twitter', 'facebook', 'instagram' ); // loop through each foreach($sites $site){ $var = '<img src="'. get_template_directory_uri() .'/images/social/'. $site .'.png">'; echo $var; } ?>

php wordpress

No comments:

Post a Comment