1

I wish to add a div class INSIDE of this echo:

  <?php echo get_image(); ?>

Not sure what I am doing wrong. The div class must be inside (wrapper is no good). Any suggestions?

Here are some examples of what I've tried (none work):

 <?php echo '<div class=mydiv>' get_image();  ? '</div>'>

 <?php echo '<div class=mydiv>' .get_image();. '</div>' ?>

Thank you!

2
  • 4
    <?php echo '<div class=mydiv>' .get_image(). '</div>' ?> try this remove semicolon after get_image() Commented Dec 18, 2015 at 4:52
  • 1
    Make sure that get_image() returns a stringable result too, even though I am guessing it does in this context. Commented Dec 18, 2015 at 5:14

3 Answers 3

3

Remove the semicolon after get_image function, also add the double quotes for classes name as echo is started with single quote.

<?php 
   echo '<div class="mydiv">' .get_image(). '</div>';
   echo '<div class="mydiv">' .get_image(). '</div>'; 
?>
Sign up to request clarification or add additional context in comments.

Comments

2

First thing is, you can't use semi-colon(;) in the echo method, if you are using another method inside it. For that you can use this code:

PHP

<?php
    echo '<div class="your_class_name_here">' .get_image(). '</div>';
?>

Comments

0

If it gets more easy, you also can also do:

<?php 
echo "<DIV CLASS='yourclass'>"; get_image();
echo "</div>";    
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.