I tried to write some snippet with the help of WordPress codex. Please check below and update it further as per your needs. I hope this helps:
global $post;
$args = array(
'numberposts' => 1,
'order' => 'ASC',
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_status' => null,
'post_type' => 'attachment',
);
$attachments = get_children( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'full' );
echo wp_get_attachment_url($attachment->ID);
echo '<img src="' . wp_get_attachment_thumb_url( $attachment->ID ) . '" class="current">';
}
}
Related Posts:
- How to manage attachment relationships for specific posts in WP 3.5+
- How to trigger a refresh in the media modal
- How can I bulk delete media and attachments using WP-CLI?
- Expanding new Media Uploader in WordPress 3.5
- Uploading Multiple Attachments From Front-End With A Description
- Get all posts (of any post type) an attachment is used in
- How to single click to download image in single post
- Unattaching unlinked images
- Delete attachments from Front end
- Get attachments (get_posts) and WP 3.5 new uploader
- How to count media attachments?
- How to make a customized “Create Gallery” tab in the ‘Add Media’ window?
- How to retrieve alt attribute for an attachment (uploaded image)?
- Show attached media image if no thumbnail image detected
- media ‘path’ issue / concern when bringing files live
- Media library quick/inline edit
- How to compress image before inserting to wordpress using wp_insert_attachment function?
- Massive photogallery import
- the_time() returning wrong date/time (way in the future)
- Gutenberg Block: Image resolution
- Media Library Mess After FTP … /uploads
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Setting an image as post header (not featured image)
- Using the GetMediaLibrary() method in python-wordpress-xmlrpc.media, how to iterate over the result?
- Remove attached media
- Get all post attachments except featured image
- Stop WordPress from reserving slugs for media items?
- Changing attachment urls?
- Add custom class to attachment in media library grid mode
- How can I UN-attach media from a post?
- Password protect some uploaded files, so only logged-in users can view them
- How to get attachments for a specific post type?
- How to add media from front-end to an existing post?
- Make individual attachments private?
- exposing attachment uploading to the front end — delicate
- Get the attachment URL on single.php
- How to get list of paths (not urls) for an image
- Insert custom ID into wp_get_attachment_link
- How to add attachment without uploading?
- Reorder “menu order” of attachments to another predefined order
- Change code to display image attachment page
- Add image attachment to post via coding?
- How To Grab All Type Of Attachments, But Images?
- Removing width and height attributes from wp-get-attachment
- Change filename during upload
- Get post attachment images dimension and use in embed code
- use wp_get_attachment_image() to show attachments
- List Post Attachments – Remove Image Thumbnails
- How to fetch only media that was already attached to a post/page?
- How to set a conditional statement for $attachment->post_excerpt, to check for value?
- Post edit – Media Library – Only get images from current post
- wp_mail not sending attachment
- How to check if there is image title, caption, description?
- Password protect media attachment – share across guests
- How to remove attachments size attribute [duplicate]
- Handling image uploads without thickbox
- hook wp_generate_attachment_metadata does not read all the attachments
- What is the way to add additional fields to attachments in 3.5+?
- Auto create file and send it via wp_mail()
- how to get random media id from media gallery
- Attach pdf from dynamic url
- Post Gallery list attachments except the one used as post thumbnail
- Echo Permalink in Attachment outside of loop?
- How can I display a link to a post’s (Word doc or pdf) attachment?
- GUID field in wp_posts – relevance for attachments?
- Is there a function for getting the post/page that an attachment is related to?
- Prevent image from being accessible via url as a post?
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- get_post orderby not working in plugin
- Delete child post and attachment links to parent post
- Remove attachment from database
- Display Audio Attachment URL
- changing the default picture size link url
- Theming media inserts
- File Attachment display title in template
- add image caption
- Do custom post type (CPT) attachments/media store the parent post ID?
- Get all post embedded images
- Shortcode for Custom Field of Media Attachment (to use with Featured Images)
- Programmatically Altering Gallery Link and image size?
- Append Media/Attachment IDs to Gallery Shortcode HTML Output
- File was uploaded, but it is not shown on media section of the dashboard
- wp_get_attachment_metadata is empty
- Restricted Attachments/Change Attachment Upload Location
- Hide Image Container if No Image Attachments
- How to link images to attachment.php [duplicate]
- Check whether attachment ID is associated with more than one post?
- How to remove attachments from main query via pre_get_posts?
- Post attachments doesn’t show after manual db import
- Possible to “Attach” images to multiple posts without uploading twice from Add media Section?
- How to get boolean if file A is attached to post B
- ID of images from gallery
- WordPress Attachments vs Post Meta
- open image after clicking on single.php with different stylesheet in wordpress
- WPML : how to pick a featured image only once for different languages?
- How do I get link URL (not file URL or attachment URL) of an attached image [duplicate]
- Attachment page custom title?
- No attachments on contact form 7
- Give attachments an archive page, and exclude unattached ones
- wp_mail attachment not working in wordpress