You’re getting the size as the $size
as the 4th argument of your callback function. You just need to use an if statement to check it:
function thumb_bookmark_html( $html, $post_id, $post_image_id, $size ) {
if ( $size === 'thumb-bookmark' ) {
$html="<a class="MyClass" href="" . get_permalink( $post_id ) . '" alt="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
}
return $html;
}
add_filter( 'post_thumbnail_html', 'thumb_bookmark_html', 10, 4 );
Also note that I changed 3
to 4
in the add_filter()
function. This ensures that I get all 4 arguments in the callback function.