Skip to content

Instantly share code, notes, and snippets.

@pauloiankoski
Created February 11, 2015 12:24
Show Gist options
  • Save pauloiankoski/1f33285ae4bd7fa9431e to your computer and use it in GitHub Desktop.
Save pauloiankoski/1f33285ae4bd7fa9431e to your computer and use it in GitHub Desktop.
Adiciona uma imagem padrão ao the_post_thumbnail
// Adiciona uma imagem padrão ao the_post_thumbnail
function add_default_image_to_the_post_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
global $_wp_additional_image_sizes;
if( ! $post_thumbnail_id ) {
if( is_array( $_wp_additional_image_sizes[$size] ) ) {
$sizes['width'] = $_wp_additional_image_sizes[$size]['width'];
$sizes['height'] = $_wp_additional_image_sizes[$size]['height'];
} else {
$sizes['width'] = get_option( $size . '_size_w' );
$sizes['height'] = get_option( $size . '_size_h' );
}
$html = sprintf( '<img src="http://placehold.it/%1$dx%2$d/F5F5F5/&text=Sem+Foto" width="%1$d" height="%2$d" />', $sizes['width'], $sizes['height'] );
}
return $html;
}
add_filter( 'post_thumbnail_html', 'add_default_image_to_the_post_thumbnail', 999, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment