There was a lotta junk in that function, here’s all you need:
function get_post_image() {
global $post;
if ( preg_match( '/<img.+?src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches ) )
$image = $matches[1];
else
$image = get_avatar( $post->post_author );
return $image;
}
Related Posts:
- Getting the current author (it has changed) of a post, not the original author
- removing inline styles from wp-caption div
- How to get Images included in Post
- Find the post an attachment is attached to
- WordPress: How to get the current logged in author page URL?
- How to add editor’s name to entry meta byline?
- Download external images if post is publish
- Can I load posts via Ajax?
- Show the title of the latest post by author
- Unattaching images from a post
- how to display post content without post image?
- How to wrap every image in a post with a div?
- Get current users post URL?
- Filter posts by author and category simultaneously
- Load post content into div with ajax
- Add an image box besides featured image?
- Limit function to specific post category
- Remove inline width from figure
- WP rest api returns 404 only when author param is used
- Remove permalink from images when inserting into post
- WordPress Theory Lesson – Image Columns within posts with alignment?
- Get image from post’s gallery
- Copying and pasting emoji in a wordpress post
- Guest Author – How to display posts on /author/ archive page
- How to display featured image without it appearing in post?
- Featured Image uploaded, attached and set but only appearing in the media library
- creating front end image uploader that uploads images as posts
- Errors when uploading images in WP 3.5
- Show posts by a custom post author
- Get all attachment by post excluding featured and content inside
- wp-cli post create & media import issues
- Get attachments for posts that belongs to a specific category
- Get all images in post and comments like Twitter before post title
- Issue where WP Featured Image will not display
- Display Notification Bar on Header on Certain Post Count
- obtain the author id given the post id
- Thumbnail Image to go in the post aswell
- Get all comments of author’s posts
- Remove Featured Image & All Media Uploaded to the Post
- preg_replace not removed “class”
- static landing page leading to author specific pages w/ “live” content
- All Posts Linking to Author Posts directly
- Upload attachment from external site
- Get URL from all images in a post
- Disable posts generated from image uploads
- How to get the ability to change the author of a post
- Echo Text If User Is Logged in But NOT the Author of post
- Images showing up in Post Editor, but not in Published Post
- Image behind the post’s title
- Only allow posts with a specific term to only be viewed by other authors with the same term in their post
- How to retrieve certain number of images from a wordpress post?
- How to limit author related post listing ?
- Get total post from an author
- Send email to author of post on post submission
- Show more than 200 images in one post
- Image on rss feed on post
- Change the background of each post according to the category
- Get latest author posts inside the loop
- Where to insert the other site image url for our wordpress post
- select post preview image from nextgen gallery
- Simple Local Avatar Plugin
- How to get the next and previous image title from attachment or gallery?
- Authors’ Links on Homepage Not Going to Author Post Pages
- adding my posts (author posts) in menu
- Aligning images in the wp editor not working. How do i get this to work in custom theme?
- unable to write to the database while uploading images
- Restricting displayed posts to posts from only select authors
- Change of author not updating
- Limit Post Creation Count by Author or Role
- Display image gallery if more than 1 image
- Post images are not displayed in media library
- Delete attached images from posts
- Center crop the feature image
- Schedule image post on download
- Add another feature image box
- ‘posts’ table should not store the absolute image path
- How to make an image appear as a thumbnail in the blog post?
- Set featured image on creating new post
- Custom author search
- How can I alternate styling of images in a post? [closed]
- List of authors posts minus very latest
- Customizing individual images on posts
- Update all images url imported from HTML pages
- show latest authors blog post
- Featured Images link to post parent
- Getting posts from multiple users?
- Display the current post author and his url in the post header
- Post thumbnail dependant on category
- Latest news mini images
- Show last post of employee in his profile page
- Only show posts with image and the correct ammount of posts in loop
- Notify Author of the post if admin deletes his post and perform some function
- Extra Theme – Fit image inside of Featured Post Slider
- Get attachment if matches a variable
- how to show all type of author posts in author page (SOLVED)
- How to show total view count across all posts for an author
- Full width images within post content
- Add author section on Author archive posts
- How to make the Post Author name fixed as “Editorial Staff” even if there are multiple authors?
- Download button under all images WordPress