Some Attachment IDs have changed
-
I just noticed that some images in many blog posts do not display:
example, search for Trompe L’oeil Interior With Inner Compartment Door Partially Open which is the caption of an image that doesn’t display.
After some experimenting, I figured out that this is because the attachment ID in the caption shortcode doesn’t match the ID of the real attachment, and my caption shortcode filter depends on that ID being correct. Here’s the filter in my theme:
function ria_img_caption_shortcode($val, $attr, $content = null){ extract( shortcode_atts(array( 'id' => '', 'align' => '', 'width' => '', 'caption' => '' ), $attr) ); $id = preg_replace("/[^0-9,.]/", "", $attr['id'] ); $image_attributes = wp_get_attachment_image_src( $id, 'large' ); return '<figure>'. $id . '<a href="' . wp_get_attachment_url( $id ) . '" >' . ' <img src="' . $image_attributes[0] . '" />'. '</a>' . ' <figcaption>' . $caption . '</figcaption>' . '</figure>'; } add_filter('img_caption_shortcode', 'ria_img_caption_shortcode',10,3);
The image still displays in the visual post editor (because it just uses the href, and not the ID), and the image is still attached to the post, but has a different ID.
Attachment IDs are supposed to be permanent, right? I have used the Regenerate Thumbnails tool in the past – would that have changed some of the attachment IDs?
Thanks
- The topic ‘Some Attachment IDs have changed’ is closed to new replies.