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?
- 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 add a 2nd “featured image” to a post?
- get_attached_media() returns empty array if media file already used by another post
- Insert an image into a post by API
- add_image_size is scaling, even though crop is set to true
- Programatically creating image attachments from local URLs and setting featured image
- How do I get gallery thumbnail URL and change the default thumbnail size?
- 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
- Replace Home with image link inside custom header menu
- Featured Image Size
- Change display of featured image for pages in twenty seventeen theme
- A mystery 300px image size
- 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?
- 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?
- 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?
- Reactor Theme: Prevent Post Thumb on Post
- Inserting images in multiple posts native gallery
- Changing Header Image Every N Minutes/Seconds
- Do not display post images on front page
- Redirect to another page using contact form 7? [closed]
- 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
- Are seven additional image sizes are too many?
- Remove link on full-size images
- How to hide image-url if no attachment?
- Full width featured thumbnail
- How to fix WordPress images not showing up in local hosted XAMPP server?
- View list of all attachments on site
- Change Image Sizes for Mobile Theme
- Stop WordPress from showing images on non post pages
- How to add cropped custom header image?
- Is there a way to serve different resolution images to different devices?
- Designing a custom archive.php inspired by the Autofocus theme
- Post Featured Image Custom Sizing?
- How to echo images Urls from a wordpress post, that are relally in the post
- Image cropping isn’t working correctly when using Offload Media
- Created blank theme for REST API, featured image not appearing on admin side
- Responsive Images with art direction
- Uncaught Reference error in Retina.js
- Can’t upload images on new theme
- Images use & location, on new wordpress theme
- image sizes – finding and removing
- Troubles with code for upload a image
- Full width thumbnail
- Adding a Class to an Getting From Post Content
- Create image with imagepng() (fails at header)
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- How to store and retrieve the attachment alignment?
- Change default options on attachment page
- How do I keep images in posts below a certain size without editing the post?
- the_post_thumbnail fetches wrong image
- Custom image size doesn’t work
- Retina ready for uploaded images which are cropped
- How to force unlink on attached/inserted images?
- Add rel to all images in a post
- Display Page featured Image as well as Posts featured Image
- How can I add a single image from a gallery into the page header?
- Custom Theme functions.php – Using add_settings_field and input type=”file” to set custom logo
- How do I work with responsive images in WordPress? (img srcset/sizes)