apply_filters( 'post_thumbnail_html', string $html, int $post_id, int $post_thumbnail_id, string|int[] $size, string $attr )

Filters the post thumbnail HTML.


Parameters Parameters

$html

(string) The post thumbnail HTML.

$post_id

(int) The post ID.

$post_thumbnail_id

(int) The post thumbnail ID.

$size

(string|int[]) Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).

$attr

(string) Query string of attributes.


Top ↑

Source Source

File: wp-includes/post-thumbnail-template.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
2.9.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by João Carvalho

    Add title attribute to post thumbnail:

    function wpdocs_addTitleToThumbnail( $html ) {
        $id = get_post_thumbnail_id();
        $alt_text = get_post_meta( $id, '_wp_attachment_image_alt', true );
    
        $html = str_replace( 'alt=', 'title="' . esc_attr( $alt_text ) . '" alt=', $html );
    
        return $html;
    }
    add_filter( 'post_thumbnail_html', 'wpdocs_addTitleToThumbnail' );
    

You must log in before being able to contribute a note or feedback.