I have one template file for the main page, after creating home page I have added text to check if it reflect changes on my home page or not and it was successfully displaying text. But when I try to add image by clicking on add media option then image is uploaded but not displaying on my page. What piece of code should be used to get this image on my template file or any other suggestions?


if You wish to display an image, which is a thumbnail of a post, then use:

  <?php echo get_the_post_thumbnail( $pageID, 'thumbnail' ); ?>

if You wish to display an image from media, then use

<?php echo wp_get_attachment_image( $attachmentID, 'thumbnail' ); ?> 

thumbnail is set for size and is set by default. Size can be changed to medium,large or full

if You want to display a specific image, just insert the img tag

There are more ways, this are the basic ones, which are enough. Good luck

  • Thanku@ Jurij, but if I want to change the image from dashboard, by simply clicking on media on that particular page without going into the template file or coding area, then I am unable to do this by above technique.By mentioning image id or attachment id the image has been fixed like hardcoded. – nomeer Aug 5 '15 at 9:21
  • i guess you will have to create a plugin to provide this functionality. I would add a column to the attachment database table and set it to 1 if it is nedded to be displayed. – Jurij Jazdanov Aug 5 '15 at 11:20

you can add any custom field with this module https://wordpress.org/plugins/advanced-custom-fields/. And can easily add it to your pages and posts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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