There isn’t really a built-in way in WordPress to determine if a content field has an image in it, but you can use standard PHP functions to check. For example, I’ve used a similar technique to check if a post’s featured image has also been inserted into the post content, and if so, haven’t shown the featured image again.
You haven’t included any of your code, so this is just a sample you’ll need to work in to what you already have.
The strpos()
function will tell you if a specific string is inside another string. For example:
if( strpos( get_the_content(), '<img ' ) ){ /* this content has an image */ }
You could perhaps use this to add classes to your content container, so you can treat it differently in the CSS:
<?php
$image_class = strpos( get_the_content(), '<img ' ) ) ? 'has-image' : 'no-image';
?>
<div class="post-content <?php echo $image_class; ?>">
Related Posts:
- Auto Add Image Title,Caption,Alt Text,Description while uploading Images in WordPress
- How to set the default embed image size
- Pasting images removes class attribute
- Ability to edit image via WYSIWYG
- Check if page/post has any anchors that link to an image jpg/gif/png
- Random popup image per user with no repeat
- Get full image array
- ACF Image ID, echo the alt tag
- alt tags of the images are not saving/emtpy
- How to remove p tags around img and iframe tags in the acf wysiwyg field
- ACF Wysiwyg Editor Image srcset for responsive images [closed]
- How do I retrieve an image’s width and height using Advanced Custom Fields?
- URL through custom field returning null
- Alt Image WordPress [closed]
- Initializing the cropper for image uploads
- WordPress and Advanced Custom Fields and Flickity
- List sub pages with custom field content converting image ID to URL
- Image to only show up in the single post page, not on the blog/home page
- How do I embed an image at actual size?
- How do I add a nested conditional within an echo – to use a default image if there isn’t one in the post?
- How to get the attribues (alt and title) of an image import with ACF [closed]
- Generate / attach Image srcsets from ACF Image Field
- How to change image type for specific size?
- What’s the proper way to find and remove duplicate images from posts and the media library?
- Mixed content warnings after changing site adress from HTTP to HTTPS
- Insert an image into a post by API
- Creating a rotating header /image slider using theme customization
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- No srcset for hard-cropped thumbnails
- Slider image issue in wordpress
- Getting custom size image URL
- Retrieving images from a NextGEN gallery
- Query for recent images across multiple posts
- Getting alt text of featured image
- Get image alt attribute just by image URL
- Is there a way to get attachment data?
- WordPress is stripping the Alt tag’s quote marks from images where Alt is not set, but leaving the word ‘alt’ creating problems for ADA compliance
- WordPress reduces the full size image and uses it as the original
- Show taxonomy list with taxonomy images ( SOLVED)
- get_children() not working properly – Only on one post?
- Warning: getimagesize() [function.getimagesize]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 [closed]
- Is There A Way Of Using the_post_thumbnail() to Pull In A Specific Image From The Media Library
- How to add data attribute to all images in posts [closed]
- Output random (custom) image size
- WordPress crops images differently on retina screens?
- Image thumbnails not available post migration, but still accessible via direct URL – DB issue
- How do I create an alternate RSS feed for tags with custom image sizes for MailChimp?
- Exclude images from “inserted into post” when trying to get attachments
- Move Image Captions Inside Link ( tag) if Added
- Sharing images to social media – issue with aspect ratio
- How to add custom classes to figure element only if image has caption?
- I got an issue after i migrated a site
- How to add an image to a custom url?
- 409 error (Conflict) when trying to insert an image into a post
- Facebook og:image issues after https change [closed]
- Does WP create multiple images?
- I have no images in an activated wp theme
- Understanding WordPress image sizes and responsive images
- Image large size [closed]
- Media gallery images url instead of ID on WP API Response
- Upload non-featured image to image field
- css to fit image by HEIGHT
- Some Images Disappeared from Media Library?
- Get an image from url, resize it, and save on a custom folder (not the media library)
- Get all custom sizes in srcset attribute
- Why isn’t add_image_size(‘event-secondary-image-thumbnail’, 250, 150) working?
- How to add thumbnails to posts and pages automatically in a uniformed fixed elegant way?
- How do I implement an image viewer and rotator? [closed]
- Upload images – Theme options
- Is it possible to modify default image name suffix?
- How to replace post image url before posting using api?
- Background Image Does Not Display on Page
- Can’t fix corrupted images
- WordPress Single Post image gallery as slider
- How to update an image attachment’s alt text from a custom field when saving a post?
- There is an image embedded on my page that I can’t locate in order to delete. Please help me!
- Could creation of various image sizes cause slow form submission response?
- How to add featured image use HTML
- Correct color profile and saving? Thumbnail creation?
- Allow users to upload attachments to certain posts
- How to get image ID based on get_theme_mod image URL?
- How to bulk update then save images in wordpress posts
- stop wordpress from resizing feature gif images
- Change wordpress default upload path to another domain
- Modify media file markup output
- Responsive images in Bootstrap 4 slider
- WPML – Change media uploader language
- How can I add an “Attach image to this post/page” link on the Add Media lightbox?
- WordPress Is Saving Original Image Only
- Display images from JS?
- How to make an image bigger with wp_get_image_editor
- Assign one featured image to multiple posts?
- An image on my site is showing as the wrong image [closed]
- Set padding for all content except images and few more elements
- Advanced custom fields Repeater conditional statement not working [closed]
- Orientation of featured image in post?
- WPALLIMPORT Exporting images from repeater field [closed]
- What does WordPress media uploader do to image files on upload?
- Site header logo and parallax image on homepage do not display on iPhone
- Is is possible to append .webp to srcset images using wp_filter_content_tags()?