To further clarify the problem, here is the code snippet:
function change_post_content( $post_content, $attachment_id ) {
$medium = wp_get_attachment_image($attachment_id, 'medium');
$post_content .= $medium;
return $post_content;
}
which inserts the following string in the new post:
<img width="1" height="1" src="http://zenbrett.fritz.box/wp-content/uploads/2014/05/20140501-131342mws1.jpg" class="attachment-medium" alt="Maypole and St Florian statue" />
where the image is exactly the image I was uploading
I ran into this issue as well. It could be the server making an erroneous calculation or because we’re running WP Super Cache and using a CDN—not really sure. Anyway, here’s what I did to fix the issue, which will work if you have a fixed width:
function change_post_content( $post_content, $attachment_id ) {
$medium = wp_get_attachment_image($attachment_id, 'medium');
$medium = str_replace( 'width="1"', 'width="100"', $medium );
$medium = str_replace( ' height="1"', '', $medium );
$post_content .= $medium;
return $post_content;
}
The two new lines of code finds and replaces the width and height settings if they equal “1”. Just update width=”100″ on line 3 to whatever size you’re trying to achieve. Let me know if that helps or if you’ve created an alternate solution.
-PaulMighty