bgbs Posted January 19, 2012 Share Posted January 19, 2012 I need to rewrite this php statement <img src="<?php bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" /> When I try to do this <?php echo '<img src="<?php bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" />' ; ?> It does not work, because I guess I've open and closed a php code inside php. How do I properly write this statement? Thanks Ben Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/ Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 What is html source of this code Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309349 Share on other sites More sharing options...
bgbs Posted January 19, 2012 Author Share Posted January 19, 2012 This is used by wordpress, but I know Im not properly wrapping it in echo statement Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309353 Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 what about this? <?php echo '<img src="'; bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" />' Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309355 Share on other sites More sharing options...
herghost Posted January 19, 2012 Share Posted January 19, 2012 Your are already writing in php so why are you opening another php block? try removing the <?php & ?> in the middle of your code! Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309357 Share on other sites More sharing options...
bgbs Posted January 19, 2012 Author Share Posted January 19, 2012 Quote Your are already writing in php so why are you opening another php block? try removing the <?php & ?> in the middle of your code! You mean like this? <?php echo '<img src="bloginfo('template_directory')/images/image.png" title="" alt="" />'; ?> This doesnt work Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309358 Share on other sites More sharing options...
bgbs Posted January 19, 2012 Author Share Posted January 19, 2012 Quote what about this? <?php echo '<img src="'; bloginfo('template_directory'); ?>/images/mainimage.jpg" title="" alt="" />' This will not work, because the whole echo statement needs to be wrapped in php tags. I just tried this and it is working half way echo '<img src="'. bloginfo('template_directory') .'/images/image.png" title="" alt="" />'; But it outputs, when viewing html source, as: http://site.com/wp-content/themes/mytheme <img alt="" title="" src="/images/image.png"> Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309363 Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 Could you post entire php file or at least while function or class please? Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309364 Share on other sites More sharing options...
bgbs Posted January 19, 2012 Author Share Posted January 19, 2012 Quote Could you post entire php file or at least while function or class please? It is a huge php file with pages of code wrapped in php tags. And in between those tags, I'm just trying to add a statement to output an image from images folder, and instead of echoing full url path, I'm using the wordpresses path to template folder, and how to do this properly in echo is where I'm stock right now. But as I posted above here is what I've been able to do echo '<img src="'. bloginfo('template_directory') .'/images/image.png" title="" alt="" />'; But it outputs, when viewing html source, as: http://site.com/wp-content/themes/mytheme <img alt="" title="" src="/images/image.png"> Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309366 Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 Quote Quote Could you post entire php file or at least while function or class please? It is a huge php file with pages of code wrapped in php tags. And in between those tags, I'm just trying to add a statement to output an image from images folder, and instead of echoing full url path, I'm using the wordpresses path to template folder, and how to do this properly in echo is where I'm stock right now. But as I posted above here is what I've been able to do echo '<img src="'. bloginfo('template_directory') .'/images/image.png" title="" alt="" />'; But it outputs, when viewing html source, as: http://site.com/wp-content/themes/mytheme <img alt="" title="" src="/images/image.png"> As I understand you this is what you need: echo '<img src="'; bloginfo('template_directory'); echo '/images/image.png" title="" alt="" />'; Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309369 Share on other sites More sharing options...
bgbs Posted January 19, 2012 Author Share Posted January 19, 2012 That worked! But wait, why did you have to break this to two separate echo statements? Why couldn't this be wrapped all in one echo? Thanks for your help Ben Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309372 Share on other sites More sharing options...
dzelenika Posted January 19, 2012 Share Posted January 19, 2012 function bloginfo('template_directory') doesn't return but echoes value so there's no need to include it in echo! Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309374 Share on other sites More sharing options...
bgbs Posted January 19, 2012 Author Share Posted January 19, 2012 Quote function bloginfo('template_directory') doesn't return but echoes value so there's no need to include it in echo! I see I appreciate your help. Link to comment https://forums.phpfreaks.com/topic/255377-php-newb-needs-help-with-syntax-please/#findComment-1309376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.