Jump to content

When to close and open the php tags...


qrahaman

Recommended Posts

Hello,

 

I'm having a bit of trouble with the following:

 

<?php echo htmlentities('<img src="<?php bloginfo('template_directory');?>/images/my-image.png" / rel="nofollow">'); ?>

 

As you can see, I am trying to use php to call the template directory but it isn't being recognized as a php statement.  I'm new to php and I'm pretty certain my syntax is not right.  Can someone provide a bit of guidance?  Thank you.

 

Quint

Link to comment
Share on other sites

You cannot "nest" PHP tags.  You can only open PHP tags if the previous one has been closed.

 

You want to research string concatenation.  This is correct:

 

<?php echo htmlentities('<img src="' . bloginfo('template_directory') . '/images/my-image.png" rel="nofollow" />'); ?>

-Dan

 

Link to comment
Share on other sites

I'd also add that trying to do too many things in one line of code can be confusing to the point of any possible efficiencies are outweighed by the inability to read/manage the code. I would probably do somethign such as:

 

<?php
$blogInfo = bloginfo('template_directory');
echo htmlentities('<img src="' . $blogInfo . '/images/my-image.png" / rel="nofollow">');
?>

 

Although, you do realize that the above will not be a hyperlink because of the htmlentities, right?

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.