If you have the size of the square container before hand as you do, 208x208px then why not just add a custom image size to your functions file and call that image size in your template.
Add this to your themes functions.php:
add_image_size( 'custom-size', 208, 208, true );
if you are running WordPress 3.9 you can use cropping as well so you could use it like this:
add_image_size( 'custom-size', 220, 220, array( 'center', 'center' ) );
Then call it in your template file:
$media_preview = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'custom-size') );
Related Posts:
- show hide image script after 4 seconds [closed]
- How do I disable responsive images in WP 4.4?
- Set default image sizes in WordPress to hard crop
- After Moving a Site to Another Domain, All Images Are Lost
- How to find attachment by it’s name?
- Change html structure of all img tags in WordPress
- How to disable “insert into post” only when selecting the Featured Image?
- Is there a way to define a default caption to all uploaded images
- How can I add the “Use as featured image” to a custom metabox?
- How to increase media image scale limit?
- Dynamic-Image-Resize Plugin does not output anything
- How to output placeholder image if no featured image set?
- Cannot access the thumbnails of attachment images… Cannot find the reason
- How to place an image into header.php? [closed]
- Uploading an image as featured image from frontend form
- How to upload images from my directory into my wordpress?
- Add a featured image in my theme?
- @wordpress/create-block image url in css
- How does WordPress work out the srcsets?
- How to include a picture in a blog post such that it will show in Facebook?
- Remove ‘wp-content/themes/themename/’ from Image path
- help getting featured image using get_posts
- Why html tags are being appended to my pictures?
- Why can I not view image attachment pages?
- Restrict Image Uploads to a Certain File Type
- wordpress media library shows empty images
- How to change the target size of images clicked on in WordPress standard gallery
- Image popup in a lightbox / overlay from the backend 3.5 admin area (plugin)
- media sideload image and Google Content
- Adding different backgrounds for different pages
- Mobile Featured Image Bug
- How to display alt tags in img src?
- Big Image on Featured Post, Normal on Single Post
- Making images in posts link to the image file rather than the attachment page
- offload media to external services [closed]
- How to create ‘Local’ filters for WordPress srcset sizes in template parts?
- the_post_thumbnail() image sizing problem?
- Imagick vs GD colour issues on image uploads
- How to add image and featured image to post by WP REST API
- Jetpack’s photon causes local site to try and serve images from WordPress CDN [closed]
- How to stop wordpress always displaying full-res images
- Transfer only original images to new site
- How to filter the image embed code based on link type
- WordPress PNG compression issue
- “Unable to create new image” error in wordpress dashboard image editor
- Fallback image size when using wp_get_attachment_image_src / full size compressed image
- Rewrite all article pictures to link to file
- Upload box media size not working
- Featured images disappear after DB export/import?
- I want to Add My Product Image to Admin Order Email in Woocommerece [closed]
- Remove Image Sizes in Media Settings Page
- Setting default image size
- Automatically Insert alt attribute above image has h2
- Rebuild thumbnails via WP Cli – how?
- Get ID for previous/next image link
- Changing Image Size Settings does not show in Image Details
- adding image to post thumbnail from another server
- Logo is not being displayed in header (Twentytwelve)
- Set Featured Image not opening – Stuck at loading
- Convert featured images into “product images”
- How come the images arent loading properly?
- How to use the thumbnail size with catch_that_image
- Not able to retrieve image id from sibling site within a switch_to_blog
- How to display a warning when an uploaded image is too small?
- How to link image in WordPress – Elementor when certain element does not offer that option?
- Large uploaded images not resizing?
- Having an issue in compressing Images in wordpress site
- How to generate alt attributes with php / filters?
- Word press cutting sliding images – not displaying the entire image
- Image links broken / “DNS Update Required” message
- Convert multiple image blocks to gallery block in Gutenberg?
- WordPress After migration some images src is empty
- Image sizes reset when changing theme
- How to get featured image of last post in a category?
- How can I add “alt” tag to element?
- After moving a site to new hosting, not all images are showing in media library
- Recovered WordPress installation (on localhost) links broken and images not showing
- Custom Background for each page and post
- How can the alt be added to this wooCommerce category image?
- Media sizes do not appear
- How to make Facebook share the featuterd image from url on WordPress
- Changing current post image uls with a function
- Delete images of a particular size
- How to watermark wordpress images from wp-content/uploads folder with htaccess and php?
- How to display every pictures from all the posts on one page?
- How to add multiple images in a page
- Images not rendering
- Retrieving Image Storage path
- Add category description to list of category with taxonomy image
- how to display all images from their siblings/ from same parent?
- How do add custom class and id to the that is generated from media gallery insert image into post [duplicate]
- How do I get the URL of only the first picture in a WordPress post?
- Specify what to do for a specific image number of the post
- adding images to wordpress pagination?
- How do you change all images dimensions to have the same size?
- Images getting corrupt automatically
- Thumbnail size keeps resetting automatically
- WordPress Missing Images
- Display first image’s caption
- The uploaded images are only full-size (original)