You should add your custom image size with this code:
add_image_size( 'my-test-image-size', 148, 148, true );
Then in your template file you can get cropped image using wp_get_attachment_image_src like this:
$attachment_id = ...; // i.e. get_post_thumbnail_id()
$image_info = wp_get_attachment_image_src($attachment_id, 'my-test-image-size');
echo '<img src="'. $image_info[0] .'" ... />'; // $image_info[0] contains url of cropped image
To be more precise… wp_get_attachment_image_src
returns an array containing:
- [0] => url
- [1] => width
- [2] => height
- [3] => boolean: true if $url is a resized image, false if it is the original.
Related Posts:
- How to disable WordPress from creating thumbnails?
- set_post_thumbnail_size vs add_image_size
- the_post_thumbnail responsive srcset not populating with custom image size
- New image size version only for the Featured Image file
- Can WordPress crop only the post thumbnails?
- Autogenerated Thumbnail compression depending on size
- How check that there is post thumbnail feature image or not on wordpress?
- If I Regenerate Thumbnails, would WordPress delete the existing Thumbnails and replace them with ‘new copies’?
- “Medium” size image displayed instead of “thumbnail” in only one post, other posts are fine
- How to create resized versions of images added with wp_insert_attachment
- Thumbnails are hard cropped not matter what
- Featured image size always cropped bottom
- Trouble Retrieving Thumbnail URL on Front-Page
- How to get image title/alt attribute?
- Generate Thumbnails only for Featured Images
- Set custom name for generated thumbnails
- How to add multiple image sizes of the same size with add_image_size
- wp_get_attachment_image_src always returns full-sized image
- Can’t extract and set SVG dimensions
- get_the_post_thumbnail_url with an unregistered size
- How to change the naming of the resized image files
- Allow user to manually set crop area of default/custom image sizes on upload [closed]
- No srcset for hard-cropped thumbnails
- Resizing Images to lower Disk Space Using Plugins
- How to change _wp_attachment_metadata specific value in SQL?
- Only create image size when used in featured image
- How to use images uploaded with custom implementation of thickbox like the_post_thumbnail() functionality
- add_image_size and add_filter(‘image_size_names_choose’, ‘my_custom_image_sizes’) not working with wordpress 3.5.2
- Customising the size of images served in Visual Composer elements [closed]
- How to scale up post thumbnails/featured image?
- Upload 3 different featured image sizes to WordPress
- Disable wordpress image sizes generation
- Media thumbnail for custom post inside post content
- Thumbnail and Featured Image With Fixed Sizes?
- List category posts – Thumbnails are not displaying
- Save image as featured image
- Why am I getting errors in product.thumbnails.php? [closed]
- WordPress Uploader Editor shows broken image
- Thumbnails produce unwanted gray pixels on white background [closed]
- How to get full absolute url for post attachment?
- Is there a way to change a post’s thumbnail image(s)?
- thumbnails are getting clipped down, want to resize instead
- Force WordPress to strip/remove EXIF/IPTC metadata when resizing thumbnails
- Is it possible to nest get_previous_post()?
- How to offset thumbnails to the center?
- Sidebar Thumbs Squished?
- Aligning the thumbnail image
- How to stop thumbnail generation from some images and different size thumbnail generate
- How do get post thumbnail into plugin?
- how to link post-thumbnail to original img in a lightbox?
- 2 image size for post
- adaptive featured images wordpress 4.4 grid
- Add padding while generating thumbnail
- How can I see where in my themes and plugins certain image sizes are used?
- Can’t generate thumbnail images
- How to both crop (with tool) and resize thumbnails having only a max width constrain?
- How to fit image to Thumbnail canvas size?
- Custom image size in the_content loop
- remove and disable image link in functions.php
- Display featured image file size, extension, filename, type, orientation?
- get_the_post_thumbnail(‘thumbnail-name’) always returns empty string
- the_post_thumbnail(‘my_image_size’) always outputs full image
- Filter for post_thumbnail: link to small src and add data-attribute [duplicate]
- Get thumbnail image according to the screen
- Image with large file size not cropping
- What can I do if I set a gif as featured image? no thumbnail when i share on facebook
- Can’t get post thumbnail to display in foreach loop
- Trying to show link “Use as featured image” from Attachment window from t31os script
- Images uploaded on frontend display correctly but not in media editor.
- get_post_thumbnail does not display thumbnail
- Make image full width
- Else/If Statement to Display Photo Descriptions
- Category page with thumb is ok but can’t do the same with tags
- Dynamically determine the width and height of a image file to be cropped & uploaded AFTER form submission given fixed aspect ratio
- Is wordpress compressing my images? if so, how to prevent it?
- how can I call a posts featured image in any template?
- How to add thumbnails to posts and pages automatically in a uniformed fixed elegant way?
- Different thumbnails for index and article page
- Attachment Image using wrong src?
- Create an instance of add_image_size
- custom image size not being fetched
- Thumbnails not being generated for PDF files
- Display Multiple Photos as Featured Image when mouse moves on to it post
- How to use default image as featured image by implement some code in function.php
- WordPress Multisite: Images moved to /sites/1?
- display div tag only if post has thumbnail
- I cannot upload images to post or the media library in wordpress
- Why image Thumbnail url is not displaying with custom size?
- Does WordPress have a way of changing the ‘Natural’ size of uploaded images?
- Featured Image, and Image in post
- Allow ‘Set featured images’ to select multiple images
- Why wordpress doesn’t generate thumbnails?
- get the post thumbnail returns the full size
- Always generate thumbnail after sideloading image
- Making a thumbnail if there exist a link with. jpg or .png extension in WordPress
- Custom image sizes are not used
- I would like my posts to pull my custom cropped thumbnail instead of creating its own thumbnail from Featured Image
- Automatic adding thumbnail to post
- How to modify Media Library images DPI [ image quality down to make small in size ] [closed]
- wordpress featured image