Here’s what I use in Dave’s WordPress Live Search to get the first image:
public static function firstImg( $post_content ) {
$matches = array();
$output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches );
if ( isset( $matches[1][0] ) ) {
$first_img = $matches[1][0];
}
if ( empty( $first_img ) ) {
return '';
}
return $first_img;
}
Related Posts:
- How to add post featured image to RSS item tag?
- How do I remove featured images and captions from a wordpress RSS feed?
- How to grab first image attached to post and display in RSS feed?
- Getting images to show up in RSS Reader
- Get featured image from post on RSS feed
- Fetching full size featured image to insert in RSS Feed
- How to have featured image show in standard RSS Widget
- How to import linked images and make them featured -> automagically
- Add Custom Fields to Custom Post Type RSS
- Delete original image – keep thumbnail?
- How to add multiple image sizes of the same size with add_image_size
- change set_post_thumbnail_size according to post type admin page
- Can’t extract and set SVG dimensions
- Getting Thumbnail Path rather than Image Tag
- Image uploader with “Set Featured Image” link on front end
- adding an id to the_post_thumbnail
- How can I display my featured image correctly inside my single posts?
- Featured image upload finished hook
- Generate thumbnail for images with the same size as thumbnails
- Implementing Zurb’s Interchange Into WordPress
- How to flush feed? Or set timeout on feed so that it isn’t cached?
- How to get_posts having post thumbnail?
- WordPress gallery ‘post_gallery’ filter doesn’t work with feeds?
- How to remove CPT comment feed from head?
- WordPress Permalinks %postname% for RSS2 Feed URL
- Customising the size of images served in Visual Composer elements [closed]
- Difference between the 4 Built in RSS Feeds?
- How to scale up post thumbnails/featured image?
- Get Ancestor featured image
- Change size of featured image in Edit Post screen
- Thumbnail and Featured Image With Fixed Sizes?
- How to Create RSS Feeds for categories in WordPress?
- How to add custom fields in rss feed
- the_post_thumbnail ignores size parameter
- Is there a way to change a post’s thumbnail image(s)?
- Confused with the loop and repeating things
- WordPress thumbnail settings change
- Using concatenate with WordPress Thumbnail
- Looking for Add Title Tag on Feature Images on WP
- Changing RSS feed URL structure
- Various WordPress Feeds for Same Blog
- Custom RSS feed with custom url
- WordPress – Sync wordpress post with JSON feed
- Is it possible to nest get_previous_post()?
- Feed links not working even with add_theme_support(‘automatic-feed-links’)
- Remove a div from RSS feed
- Notice: Trying to get property of non-object when trying to get thumbnail URL
- How can I see where in my themes and plugins certain image sizes are used?
- Custom image size in the_content loop
- array set title and alt in the_post_thumbnail
- Get thumbnail image according to the screen
- Displaying Post Featured Images on All Pages
- Use Featured Image of Post as Header Image
- Recent posts on homepage: different thumbnail based on logged in status and post category
- How to display featured image description and title?
- Images uploaded on frontend display correctly but not in media editor.
- Make image full width
- Facebook Does Not Grab Correct og:Image
- WordPress 4.4 responsive sometimes doesn’t work
- get_the_post_thumbnail($post->ID, ‘thumbnail’); not working. How can I solve this?
- Is it possible to add the_post_thumbnail to style.css?
- Getting featured image of particular size.
- Different thumbnails for index and article page
- Smaller thumbnail in the_content
- Get post featured image id with $wpdb
- Attachment Image using wrong src?
- Unable to set Custom “Link URL” for Featured Image, and More?
- On what point (hook) does the_/has_post_thumbnail() load?
- I need to change the attribute of the isPermaLink guid in the WordPress RSS feed – from false to true
- First Image not loading on Mobile Version of Website
- Thumbnails not being generated for PDF files
- Is it possible to set Featured Image using HTML?
- Set featured image from auto generated video thumbnail url php
- Use Post Title as alt text for Featured Image
- Modify RSS feed to change iframe structure
- How to cropped thumbnail image without distorting it?
- RSS Feed cURL error 52?
- wp_get_attachment_metadata()[‘image_meta’] fetch WP metadata or EXIF?
- White Blank screen and issue to get thumbnail in
- Set Featured Image Based on Custom Field
- Post thumbnail on specific template
- Using lower resolution/size images for thumbnails on posts index
- Autoblog posts in wpms(network) into main site including featured images
- Link from Thumbnail to Post not working
- Featured Image metabox (postimagediv) doesn’t appears when it should
- Thumbnails not showing in blog
- Featured Image inserted through custom query, does not show up
- Change role’s settings influence post-thumbnail
- Wrap Featured Image in a Link
- Thumbnail images
- Featured Image Thumbnail Sizing
- Featured Image Isn’t showing with cropped, How to show it?
- WordPress Plugins Feed Error, but I’m not asking for a plugins feed
- WordPress not showing the latest articles in RSS feed
- How to add text & call to action button to featured image on homepage?
- Featured image as background in a div using headway
- WordPress Feed Error [closed]
- php code for image fetching
- Strange image artifact on font-page thumbnail image
- Replace category titles inside RSS feed