This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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.
Example 1: Applying the Filter
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);
Example 2: Removing a Filter
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.
Example 3: Conditional Modification
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:
- $shape: (string) Thumbnail image shape. Either ‘rectangular’ or ‘square’.
- $thumbnail_id: (int) Attachment ID.
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.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.