James
James

Reputation: 979

ACF Images are not Displaying

I am just learning the basics of Advanced Custom Fields and have a question. I am trying to post a block of information that shows a title, thumbnail image, and description. I'm using the Simone theme for Wordpress by the way and haven't really started to style it yet. Within my content-single.php file, I am having trouble with the following code:

<?php the_content(); ?>
<?php 
   if(get_field('content_description')) {
      echo '<div class="description-box">';
      echo '<h1>' . get_field('certain_title') . '</h1>';
      echo '<img src="get_field('certain_image')">';
      echo '<p>' . get_field('certain_description') . '</p>';
      echo '</div>';
   }
?>

The description-box is simply the container with a background, width, and margin applied to it. It is what holds the contents. When I get rid of the 6th line from the code above (certain_image), I get a desired output:

As you can see, the title and description output just fine, however the image field does something weird when added to the code and essentially makes everything disappear in the browser when used. I would like to guess that it is making everything collapse (hence vanishing from browser).

You should note that my single post displays as the following when using the above code:

And when I click on the post, the following seems to occur:

Just incase, because I am sure this will be asked, my image field's return value is set to be an Object. I also am using MAMP for this. The code in the content-single.php file is being implemented within my child theme.

I have this feeling that I am getting screwed up because <img> does not use a closing tag like <div> and <p> in my code. I am also sure this is not the only issue =P

Upvotes: 0

Views: 1947

Answers (1)

David
David

Reputation: 5937

you have a php syntax error - you should turn on php errors btw...

Anyway this line:

  echo '<img src="get_field('certain_image')">';

Should be

 echo '<img src="', get_field('certain_image'), '">';

or

 echo '<img src="'. get_field('certain_image'). '">'; 

Upvotes: 1

Related Questions