Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7725213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:52:56+00:00 2026-06-01T04:52:56+00:00

I have to add image as attachment in post in wordpress. Currently image is

  • 0

I have to add image as attachment in post in wordpress. Currently image is set as a part of Post content but i have to display a attachment link in post so users can download that image via attachment link.

Thank you,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:52:57+00:00Added an answer on June 1, 2026 at 4:52 am

    If you will always have only ONE image – it will be better to set it as “featured image” and then :

    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'your-image-size' )
    

    then

    echo $image[0] ;is your link 
    

    full code :

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
    <a href='<?php echo $image[0]; ?>'> my image link </a>
    

    if you do not want to use featured image – the next function will get you always the FIRST image in a post

    // Get URL of first image in a post
    
    function postimage( $echo = true ) {
        $image = get_children( array(
            'post_parent' => get_the_ID(),
            'post_type' => 'attachment',
            'numberposts' => 1,
            'order' => 'asc',
            'orderby' => 'ID',
            'post_mime_type' => 'image',
        ) );
        $image_url = ( $image ) ? wp_get_attachment_url( current($image)->ID ) : "No Image";
        if( $echo )
            echo $image_url;
        else
            return $image_url;
    }
    

    if you have more than one image the thing gets a little more complicated – and you will have to search for all attachments and loop through the array . (change ‘numberposts’ => -1, to get all)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have line: imagejpeg($this->image, $file, $quality); How can add on this image watermark.png?
I have a model Image and every image is having description. User can add
On a customer website, I have to add a background image for only a
I want to add an image, instead of the default button. I already have
I have a small problem, I have tried different solutions to add a image
I have an image 100x40 and I want to add a border to the
I have this image: What I want to do is to add a UITapGestureRecognizer
I have a image button. I wanted to add a text Search on it.
I have an image slideshow with navigation, with which I want to add an
I'm using this piece of code I found ( http://impnerd.com/wordpress-hack-add-post-images-to-your-homepage ) to display the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.