Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good evening

Add Media Library Column to Re-Attach Images

SnippetsWordPress

About a 1 minute read

"The art of living… is neither careless drifting on the one hand nor fearful clinging to the past on the other. It consists in being sensitive to each moment, in regarding it as utterly new and unique, in having the mind open and wholly receptive."

Alan Watts


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
<?php
    //Add Media Library Column to Re-Attach Images
    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>
                <?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
            }
    }