You could try something like this if you are checking the content in the main loop.
$content = get_the_content();
preg_match_all('/(<img .*?>)/', $content, $img_tags);
if (!empty($img_tags)) {
// Post content contains images, do something!
}
// Check for links and do something if you have matches
Related Posts:
- strip only specific tags (like ), but keep other tags (like )
- Removing the title attribute from links in the post content
- HTML code in Custom field
- How to wrap every image in a post with a div?
- Paragraphs removed when using get_post_custom()?
- get_post_custom stripping styling issue
- why does HTML Tag not working in Post and Page
- Content editor creating blank paragraphs in spaces and creating   in the_excerpt
- Add scripts on custom post add/edit pages Not Working
- Add code just after Post content
- WordPress’ visual editor messing up my (nested) lists (and other things as well)
- Articles are text-only in any “Category” instead of HTML
- Ajax Dynamic Archives not showing correct results
- Ajaxify This Code
- Pausing and Resuming WP_Query results
- Is Hfeed class for all pages needed
- Anyone know why wordpress converts some html entities to their numeric equivalents?
- Best Way to Add UnEditable HTML to Posts
- Divs appearing everywhere in post content
- Benefits to using semantic HTML in post content? [closed]
- Creating a WordPress Post via REST API – HTML or Markdown?
- HTML Form Submit to table in same page
- Locally change the font family [closed]
- Right align a youtube video
- WordPress 5: prevent link from displaying page title instead of URL
- WordPress Recent Post with the badge “New” on the side of the title post
- Remove HTML tags from all posts
- How to generate an HTML link automatically from URL in a users’ post
- Show all posts from the tags without having to set all of them
- Adding div to WordPress page content
- Posts don’t appear on Template Page
- How to get all the terms of a post
- CSS – Change height of Storefront / WooCommerce product categories, but not products
- Wrap posts from a category in HTML
- How can I add a custom caclulation form in post?
- How to automatically convert a form with HTML link into post
- Posts Page in WordPress loading bare HTML of my homepage
- Turn a URL into an Attachment / Post ID
- Allow variable amount of comments before pagination
- Check if post has children or not
- Create custom page in WooCommerce
- Duplicate posts
- Count singular post views automatically
- how to hide specific post from google search
- get_terms parent for current product only
- Redirection to taxonomy posts list after post submit.
- Frontend Post Excerpt field mapping
- WordPress – Hide posts in admin from user who did not write them
- How to pull blogposts using shortcodes
- What part of template to edit to remove category name from the top of posts?
- Register post status, exclude from searches
- how to get posts ids inside pre_get_posts filter?
- How to allow logged in users to post anonymously
- How to Next and Prevous Navigation Buttons on the end of the page with custom image Using Wp Post Navigation Plugin
- Custom Posts Query and meta_query Sort Order
- Exclude the first ‘n’ number of posts of a tag from home page?
- how to show single post in a custom template
- What do comments with […] mean?
- How to add category post count in main navigation menu [closed]
- How to get links to the last N posts in a specific category?
- wp_update_post question on array
- Is there any way to tell when wp_postmeta has been updated?
- Why won’t pagination work?
- Single post page breaks when post is more than 30,000 words
- Front end post submission form with duplicate type fields
- How do I include the category next to the title of a post?
- WordPress post next/prev not working
- Are post, page and category IDs unique to each other?
- Author Avatar as default first image
- Some blog posts containing source code fail to save draft or publish
- Cannot publish posts, but can create new pages
- Making a new post visible on a specific page
- Is there a way of posting or inserting content directly to the database (without entering the wp-admin)?
- Get other posts sharing the same meta values
- why my urdu text is not aligned properly when written in wordpress blog post?
- Custom Fields – How to get the list of a specific active widget each time it rendered
- Problem paginating a subquery on a post
- How to setup default value of post_id
- Google indexing duplicate page content with Page #### in post title and /page-2 in permalink instead of the ones I set
- Display post by Random Authors on Page Refresh
- How to publish a post if condition is met?
- Blogposting Schema & Structured Data without plugin
- Bulk Post update_post_meta
- More Than 50K Categories and WordPress Admin Panel Stop Showing Categories and Posts
- Hiding the name of the user who is currently editing
- allow editor/author to publish others posts but not publish their own
- Why does media_handle_sideload upload to last month’s folder?
- Random order of the 5 most popular posts
- Display result of custom form
- How can I choose and change a post title at random from an array when it is published?
- Displaying Results From Custom Taxonomy Query
- find posts with exactly 3/4 categories
- wordpress taxonomy results
- Displaying only posts from a certain category on my custom page template
- Custom post page has attributes of latest post [closed]
- get value from post to sidebar
- How to make “my posts” page
- How to have 2 posting pages on a blog
- Exclude posts by date – related post
- Post pages are redirecting to the 404 page in wordpress