Jump to content

PHP newb needs help with syntax please


bgbs

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.