siga
2/10/2017 - 10:40 AM

Creates a URL column in the media library so you don´t have to open the item to copy it. Goes to childtheme function.php (Dynamik: Dynamik C

Creates a URL column in the media library so you don´t have to open the item to copy it. Goes to childtheme function.php (Dynamik: Dynamik Custom - Functions or skin PHP file). Credits: Sridhar Katakam. https://sridharkatakam.com/add-url-admin-column-wordpress-media-library/

add_filter( 'manage_media_columns', 'sk_media_columns_url' );
/**
 * Filter the Media list table columns to add a URL column.
 *
 * @param array $posts_columns Existing array of columns displayed in the Media list table.
 * @return array Amended array of columns to be displayed in the Media list table.
 */
function sk_media_columns_url( $posts_columns ) {
    $posts_columns['media_url'] = 'URL';
    return $posts_columns;
}
 
add_action( 'manage_media_custom_column', 'sk_media_custom_column_url' );
/**
 * Display URL custom column in the Media list table.
 *
 * @param string $column_name Name of the custom column.
 */
function sk_media_custom_column_url( $column_name ) {
    if ( 'media_url' !== $column_name ) {
        return;
    }
 
    echo '<input type="text" width="100%" onclick="jQuery(this).select();" value="' . wp_get_attachment_url() . '" />';
}
 
add_action( 'admin_print_styles-upload.php', 'sk_url_column_css' );
/**
 * Add custom CSS on Media Library page in WP admin
 */
function sk_url_column_css() {
    echo '<style>
            @media only screen and (min-width: 1400px) {
                .fixed .column-media_url {
                    width: 15%;
                }
            }
        </style>';
}