You’re over-complicating your thumbnail code; all you need is this:
if ( has_post_thumbnail () ) {
the_post_thumnail( 'preview-thumb' );
} else { ....
The problem with your version is that get_post_thumbnail_id()
doesn’t accept a size parameter, so that information gets thrown away. Luckily, the_post_thumbnail()
does everything you need without having to fetch the url and build an html string by hand.
Related Posts:
- Prevent WordPress from generating medium_large 768px size of image uploads?
- Image quality based on image size
- What is a good alternative to using $content_width for image optimization?
- Can I attach image to post without adding it to post?
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- How to avoid WordPress stripping EXIF metadata when resizing images?
- Navigate with keyboard in Gallery shortcode
- How do you modify the HTML output of a Gallery item (using the gallery shortcode)?
- Can WordPress resize BMP files?
- How to include externally hosted images into a gallery block
- Insert Images at Master Uniform Height
- Link to File URL by default
- How to Display an Image Uploaded through a Meta Box in a Template?
- HTTP Error when trying to upload image
- Media sizes aren’t being created – server config?
- Drag images with caption in WP editor
- Responsive background images added inline
- How to make programmatic image upload generate thumbnail and sizes?
- Best way to strip character entities (%20 etc)
- Any way to “combine” galleries or show multiple galleries as one?
- How to remove buttons from gutenberg toolbar
- Get full image array
- Display number of images actually posted
- Confusion about arguments sent to add_image_size
- change the $content_width
- media_sideload_image with rewritten urls?
- Different image sizes for home and post pages
- Show full image thumbnail
- How to set a contact forms total size limit
- Get thumbnail url of custom meta image?
- SVG Featured image not shown in twitter
- upload featured image in custom post type from frontend
- Make medium_large images available to insert into post
- All Images on wordpress site broken
- WooCommerce-like featured gallery
- How to use photo in multiple posts?
- Creating a thumbnail from an image already on the server?
- Images not showing on blog
- Alter the image, before save, of a particular image size
- Why does Google Image Search still display my images?
- Dynamic tagged image galleries
- Hero image cropped at different dimensions
- WP fails to upload files to media library, /wp-admin/async-upload.php 403 forbidden
- How to handle a background-size: cover image in WordPress?
- Empty alt/title form check in media library
- Images stopped loadding after adding SSl
- How To Get The File Extension Of Images Having Different Extensions In A Directory?
- GoDaddy Number of Image Files Per Directory Exceeded
- Is it possible to reduce image filesize on the fly (when users enter my website)?
- add_image_size wont work after get_intermediate_image_sizes
- Ways to show multiple, separate galleries per post?
- How to get the image-URL from Media-Upload in a post?
- One of my image sizes isn’t showing up in srcset
- Featured Image Cetegory Not Shown In WordPress
- after migration, newly uploaded images won’t show up
- Why do I have blury images in WordPress
- Disable save as image on smartphones using all browsers ( chrome, firefox, ie, cm, opera )
- Using mysql to replace img src?
- wordpress add image size crop function not working in version 3.8
- Cache issues with images not showing up
- Specific Days, Specific image on Front Page
- How to change image’s author via a function when using GravityForms uploader? [closed]
- caption shortcode inserts blank paragraph
- Doing a bulk replace of images through back-end
- Serving Images from subdomain in wordpress
- Can I achieve this with WordPress?
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- SQL: How to find all attachments that are not used in any posts/pages/custom_post_types
- I would like to set a FULL SCREEN background image to all my pages (same way it is on my home page)
- How to change a theme’s footer image
- Can’t upload Images to WordPress – Error 500 Response
- Enlarge Featured WordPress Images
- WordPress 4.4.2 upload give error, can’t write is upper directory allowed to be written
- How to attach 1000’s of unattached images
- Images are not getting uploaded
- Unable to delete images in Media Library
- How to show only one image in homepage
- click on Gallery picture but pictures doesn’t appear
- How to Generate Custom Image Size in Uploads Folder?
- set specific dimension or minimum upload size [duplicate]
- Assigning image to Post-Type won’t work anymore: exceeded time?
- Content around featured image
- Getting featured image of blog page rather than post image
- How to change default image rename?
- Upload button in metabox not working
- wp_get_attachment_link() add rel attribute if the link points to direct image
- Add custom version to an image
- (Dynamically) Decrease the actual image size for downloads
- How to get some information from the_content [closed]
- Custom Background Image per Page
- wordpress images not display [closed]
- How to get customable image header?
- Delete all thumbnails & regenerate them?
- Can I turn an image into a button?
- Why are some SVG-images not visible in my footer?
- How To Get Feature Image from Blog in Same WordPress Multisite Blog on the Parent Blog?
- WPALLIMPORT Exporting images from repeater field [closed]
- Gutenberg block HTML image rendering override
- image_get_intermediate_size always returns false
- Change of displayed images for webp versions