Newsletters: Filter – wpml_post_thumbnail_img_style

Description

The wpml_post_thumbnail_img_style provides a custom inline style for the post thumbnail <img> tag. You can use this filter to add inline style based on post type or by determining the $post object and defining your own conditions. It will be added to the emails, as inline style.

It is useful when you want to modify the styling of your newsletter images and ensure the formatting remains consistent during email forwarding, as inline styles are used instead of embedded CSS classes or external styles in your email template.

Usage

<?php add_filter('wpml_post_thumbnail_img_style', 'child_theme_get_post_thumbnail_img_style', 10, 4); ?>

Arguments

  • $style – The default style (from alignment/hspace, or empty).
  • $post_id – The post ID.
  • $post_type – The post type.
  • $post –  The full post object.

Example

<?php
/**
* Provide a custom inline style for the post thumbnail <img> tag.
*
* @param string $style The default style (from alignment/hspace, or empty).
* @param int $post_id The post ID.
* @param string $post_type The post type.
* @param WP_Post $post The full post object.
* @return string The inline style string.
*/
function child_theme_get_post_thumbnail_img_style($style, $post_id, $post_type, $post) {
// Example: if the post type is 'post', add a green border.
if ($post_type === 'post') {
// Append to the default style (if any) a new rule.
return $style . ' max-width: 100%; height: auto; margin-bottom: 10px;';
}
return $style;
}
add_filter('wpml_post_thumbnail_img_style', 'child_theme_get_post_thumbnail_img_style', 10, 4);

?>

Earn Money by Referring People

Refer customers to us with your affiliate link and earn commission on sales from your link.

Sign Up

Pin It on Pinterest