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


(string) The post thumbnail HTML.


(int) The post ID.


(int) The post thumbnail ID.


(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).


(string) Query string of attributes.

Top ↑

Source Source

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

View on Trac

Top ↑

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.