If you want display an image that is inserted into your content (a hotlinked image, for example), you must use a function like this (source):
add in functions.php:
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
Then place <?php echo catch_that_image() ?>
where you want display the image.
Note: a hotlinked image just placed in your content can’t be set as Featured Image, a bultin WordPress’feature.
Related Posts:
- The the_post_thumbnail without srcset?
- Unexpected width and srcset attributes for the_post_thumbnail();
- How to set dimensions of the post thumbnails (featured images)
- Cannot get full thumbnail size using the_post_thumbnail
- Reasons why all thumbnail sizes aren’t working
- How do I Add images uploaded in the post to a default custom field
- attachment.php code or tutorial
- Add attachment for all images in post
- Getting Different Size Of Attachment Images
- How To Pick Custom Size Of Uploaded Image In Theme Via the_post_thumbnail();?
- How to disable thumbnail filter for a specific template part or image size?
- How to attach images that I “insert from url” into the post?
- How to make excerpt image be full size instead of thumbnail?
- How can I scale down the width of images in bulk that are embedded in posts throughout the site?
- Add image URL automatically to custom field?
- theme directory fallback image outputs url and not the image
- Any disadvandages if I style the wordpress align classes without img and .wp-caption prefix
- I want to resize post featured image without cropping image. How?
- WP “optimizing” PNGs into thumbnails 5X larger than originals – FIX
- optimized PNGs 5X larger than originals
- How to get image title/alt attribute?
- WordPress Theme Preview Image
- Programmatically get images by URL and save in uploads folder
- How to modify an image block in Gutenberg WordPress 5?
- How can I set image sizes and still have responsive images using the srcset attribute?
- Add default Backgrounds
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- How to find attachment by it’s name?
- How to add a 2nd “featured image” to a post?
- get_attached_media() returns empty array if media file already used by another post
- wp_get_attachment_image_attributes not working for me
- Specify image dimensions
- How to get gallery images?
- Insert an image into a post by API
- How to change post thumbnail title and alt attributes to post title?
- add_image_size is scaling, even though crop is set to true
- Featured Image in 4.4 should be larger on mobile device
- Programatically creating image attachments from local URLs and setting featured image
- How to use the responsive images feature from WP 4.4 in your themes
- Confused about image sizing business in WordPress
- How do I get gallery thumbnail URL and change the default thumbnail size?
- Adding Featured Image to Post programatically
- How to change _wp_attachment_metadata specific value in SQL?
- Responsive class to all the images in the content
- How wordpress handle upload images and how to use them in the code
- How can I get a different image size, if all I have is the link?
- How to handle thumbnails
- Replace Home with image link inside custom header menu
- Show prev and next post links for parent post of current image in attachment page?
- Featured Image Size
- Doubled titles when using All in One SEO with custom template
- How can you determine whether an image is merely attached or has actually been inserted into a post?
- Change display of featured image for pages in twenty seventeen theme
- Get attachments by user
- How to regenerate thumbnails when they’re stored on S3
- Converting Attachment to Images?
- wp_get_attachment_image_src() width and height boolean
- How to float an image in Gutenberg
- A mystery 300px image size
- Can’t show custom post thumbnail sizes as background images
- Custom Field returning Numerical Value for Image rather than URL
- Attach media to multiple posts
- Featured Images are not able to be set
- Why an arugment is missing in wp_get_attachment_image_attributes?
- Display recent posts with thumbnail
- How to make a local cache of mshots images
- Exclude featured image from attachment loop
- Change “Thumbnail”, “Medium” and “Large” image sizes using functions.php?
- image url relative path not working in css file
- Set size for attachments
- Default image size not working
- Fetch wordpress video attachment with post ID
- How do I build a post_thumbnail based archive? [closed]
- WordPress Media Uploader in page template (On Front-end)
- Responsive Images – crop don’t seem to work
- How do I include pre-installed images in a theme?
- How do I turn a post thumbnail into a background image?
- Reactor Theme: Prevent Post Thumb on Post
- How to create resized versions of images added with wp_insert_attachment
- Inserting images in multiple posts native gallery
- Can I get the ID of an inserted / linked image?
- Changing Header Image Every N Minutes/Seconds
- Do not display post images on front page
- What is the meaning of WordPress’s recommended css classes and where are they applied?
- Redirect to another page using contact form 7? [closed]
- Gallery thumbnails very small
- Featured Image meta box not showing up
- How do I remove inline style in featured image markup?
- Custom image size vs CSS sizing
- In creating a theme, how can i allow a user to change an image outside post/page content?
- Change Responsive Images Maximum Width of 1600px
- Set a featured image as a replacement to the header image
- Dynamic Post Thumbnail →
- How to show a manageable list of images on a post?
- How do you import images from a URL in your post?
- Issue on Getting Custom post type Thumbnail’s URL
- Change image size depending on page
- How to obfuscate theme directory URLs
- the_post_thumbnail() get the URL to the “medium” sized image
- Retrieve Image Attachments Getting Post Thumbnail Image First