Created
February 10, 2017 10:40
-
-
Save SiGaCode/36979dde00f461d44a2f116937660cca to your computer and use it in GitHub Desktop.
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment