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
- Add custom Attachment Display Setting for images
- Hook that get’s triggered when the author of a post is changed
- the_author() returns empty string
- Prevent Authors from viewing each others Posts
- Display Random Author with Details in Sidebar
- How to get Images included in Post
- disable WP automatically inserted line breaks after an image
- Find the post an attachment is attached to
- Delete the original big size image after upload and leave only 3 images crunched by media gallery
- Post slugs and images cannot have same name?
- Add existing images from Media Library in to custom gallery
- How to show list of posts by author and category?
- Replace image attributes for lazyload plugin (data-src)
- How do I detach images from posts?
- WordPress: How to get the current logged in author page URL?
- How to add editor’s name to entry meta byline?
- Different permalink for posts and authors
- How to display posts by current user/author in a custom page template?
- Download external images if post is publish
- How do I sort (order) the results from `get_children()`?
- upload image in a meta box
- Query posts distinct authors
- Can I load posts via Ajax?
- How do I use element instead of tags in WordPress post content having webP support?
- Restrict the Number of Posts an Author can Publish (over time)?
- Search posts by post author name
- Get the user type of an author
- How to remove images from showing in a post with the_content()?
- Show the title of the latest post by author
- Unattaching images from a post
- how to display post content without post image?
- Find most recent authors
- How to wrap every image in a post with a div?
- upload featured image from front end using wordpress add media button
- Show author post count in sidebar – Variable
- Get current users post URL?
- Get the author of the latest revision
- Filter posts by author and category simultaneously
- How do I create Comma Separated list of attached image ids?
- Custom Post Type & Author not associating, user post count is 0, api doesn’t return author in post objects
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Get post embedded image caption
- how to grab first link in post… and of course call it
- Load post content into div with ajax
- Post author is changed to admin after his post is modified by admin
- Get all posts by post_author
- Add an image box besides featured image?
- Remove image from post also removes photo from media library
- How can I control multiple editing of wordpress posts?
- Limit function to specific post category
- Multiple authors for single post without plugin
- Limit number of posts a user can make per minute?
- Authors in menu, template list post by author
- Show the author’s count of total amount of posts assign to a custom taxonomy term
- Post taxonomy from exif data
- Remove inline width from figure
- Author must complete profile info before they can publish a post?
- All my inserted images gets a link to the full image even if it is already full size image
- WP rest api returns 404 only when author param is used
- How can I list random authors from current post category?
- get custom image size
- Remove permalink from images when inserting into post
- How to get only text from wordpress post content?
- Get all images out of the posts content
- how to replace embedded “full” sized images within a post with the “large” ones
- WordPress Theory Lesson – Image Columns within posts with alignment?
- Batch process: remove first image from post content
- how can I put an image in a post with original size
- Show featured image next to post-teasers in Genesis Framework?
- Get image from post’s gallery
- How can I show wordpress posts based on author?
- Image Insert into posts and pages not working after 3.2.1 update
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Show info to author only
- Copying and pasting emoji in a wordpress post
- Auto “expire” all of an authors posts on spcific date
- How to get the user meta data for a post?
- Comma separated all attached image ID numbers except featured image ID number
- Limit posts per author role (excluding admin) in home page
- Modify Image Source With The_Content Filter?
- Guest Author – How to display posts on /author/ archive page
- How to display featured image without it appearing in post?
- Can I use images as anchor tags with
- How can I show many posts an author has per week?
- How to give capability (publish contributors posts) to author role?
- Featured Image uploaded, attached and set but only appearing in the media library
- Load post attached images on a single page site with fancybox
- creating front end image uploader that uploads images as posts
- Errors when uploading images in WP 3.5
- Format the Layout of Images In The Edit Post Textarea?
- Whitelist Author of Private Post
- Set size for attachments
- Show posts by a custom post author
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- 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