Sandeep Kumar Mishra
Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.
In WordPress, the embed_thumbnail_image_shape filter is your go-to when you want to customize the shape of thumbnail images in embeds. Whether you’re a fan of rectangular images above titles or square images next to content, this hook has you covered. To get started, you need to register it using add_filter. You can place the code in your theme’s functions.php file or, as we prefer, create a custom WordPress plugin. This way, your changes remain intact during theme updates.
Here’s how you can use the embed_thumbnail_image_shape filter to adjust the shape of your thumbnails.
function weplugins_modify_embed_thumbnail_image_shape_defaults($shape, $thumbnail_id) {
// Update the $shape variable according to your website requirements.
return $shape;
}
// Add the filter
add_filter("embed_thumbnail_image_shape", "weplugins_modify_embed_thumbnail_image_shape_defaults", 10, 2);
Sometimes, you might need to remove a registered hook. Use remove_filter as shown below.
remove_filter("embed_thumbnail_image_shape", "weplugins_modify_embed_thumbnail_image_shape_defaults", 10, 2);
Ensure you provide the same callback function name, priority, and arguments when removing the hook callback.
If you want to conditionally modify the shape, here’s a basic example.
function weplugins_conditional_embed_thumbnail_image_shape($shape, $thumbnail_id) {
if (some_condition()) {
$shape = 'square'; // Or 'rectangular'
}
return $shape;
}
add_filter("embed_thumbnail_image_shape", "weplugins_conditional_embed_thumbnail_image_shape", 10, 2);
Parameters:
If you need any customization or have any questions about using this hook, feel free to reach out to us. Visit our Contact Us page, and we’d be happy to assist you.
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.