When you upload an image or other media to a WordPress site via the “Add Media” button on a post (or page or custom type) edit page, that media is linked to that page. You can still insert that media on another post, or in a gallery on another post, but it is “forever” attached to the original post. I say “forever” because WordPress stock gives you no options for reattaching it (or detaching it.) This may be desired for many situations often involving 3rd party plugins. Your options are re-upload the media to the new post, alter the MySQL database directly or find a plugin that adds this functionality. Below is quick code that adds a link on the Media page for each Media Item.
Credit for this code goes to Andy Potanin via the WordPress forums here. Add it to your theme’s function.php file at the end. I just tested it with WordPress 3.5.1…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
add_filter("manage_upload_columns", 'upload_columns'); add_action("manage_media_custom_column", 'media_custom_columns', 0, 2); function upload_columns($columns) { unset($columns['parent']); $columns['better_parent'] = "Parent"; return $columns; } function media_custom_columns($column_name, $id) { $post = get_post($id); if($column_name != 'better_parent') return; if ( $post->post_parent > 0 ) { if ( get_post($post->post_parent) ) { $title =_draft_or_post_title($post->post_parent); } ?> <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?> <br /> <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Re-Attach'); ?></a></td> <?php } else { ?> <?php _e('(Unattached)'); ?><br /> <a class="hide-if-no-js" onclick="findPosts.open('media[]','<?php echo $post->ID ?>');return false;" href="#the-list"><?php _e('Attach'); ?></a> <?php } } |