Recent Uploads Dashboard Widget
Adds a dashboard widget with thumbnails of the 12 most recently uploaded images and files, each linking to its edit screen, so you can review new media quickly.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'upload_files' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_recent_uploads', 'Recent uploads', function () {
$files = get_posts( array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => 12,
'no_found_rows' => true,
) );
if ( ! $files ) {
echo '<p>No uploads yet.</p>';
return;
}
echo '<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(70px,1fr));gap:6px">';
foreach ( $files as $file ) {
printf(
'<a href="%s" title="%s" style="display:block;aspect-ratio:1;overflow:hidden;border-radius:3px;background:#f0f0f1">%s</a>',
esc_url( get_edit_post_link( $file->ID ) ),
esc_attr( get_the_title( $file ) ),
wp_get_attachment_image( $file->ID, 'thumbnail', true, array( 'style' => 'width:100%;height:100%;object-fit:cover', 'alt' => get_the_title( $file ) ) )
);
}
echo '</div>';
printf( '<p><a href="%s">Open the Media Library</a></p>', esc_url( admin_url( 'upload.php' ) ) );
} );
} );
Notes
Non-image files show their file type icon.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.