Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use embed_thumbnail_image_shape filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
June 6, 2023
5 minutes read

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.

Access Premium WordPress Plugins

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.

Sandeep Kumar Mishra

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.

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.