0

I'm trying to display a title, featured image, and content from a page into a new template (that will contain content from several pages). I tried to just echo the variables as shown below, but right now it's only display the content and title+"array". Any ideas?

Here is my current array:

 <?php
 $id = 2131;
 $post = get_page($id);
 $content = apply_filters('the_content', $post->post_content);
 $title = $post->post_title;
 $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'single-post-    
 thumbnail' );
 echo $content;
 echo $title;
 echo $image;
?>

1 Answer 1

1

wp_get_attachment_image_src returns an array, not a single value. Please refer to this article for more info: wordpress.org/Function_Reference/wp_get_attachment_image_src

Default Usage

<?php 
$attachment_id = 8; // attachment ID

$image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
?> 

<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
2
  • That makes sense, but I'm confused what the syntax would look like to just return the image in an image tag from my original array?
    – mtthwbsh
    Feb 20, 2013 at 1:21
  • @mtthwbsh Try this: echo $image[0]; Feb 20, 2013 at 2:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.