The admin_print_scripts-media-upload-popup WordPress action fires when admin scripts are enqueued for the legacy (pre-3.5.0) media upload popup.
Usage
add_action('admin_print_scripts-media-upload-popup', 'your_custom_function');
function your_custom_function() {
// your custom code here
}
Parameters
- None
More information
See WordPress Developer Resources: admin_print_scripts-media-upload-popup
Examples
Enqueue a custom script for the media upload popup
Enqueue a custom script that enhances the media upload popup with additional features or modifications.
add_action('admin_print_scripts-media-upload-popup', 'enqueue_custom_media_popup_script');
function enqueue_custom_media_popup_script() {
wp_enqueue_script('custom-media-popup-script', get_template_directory_uri() . '/js/custom-media-popup.js', array('jquery'), '1.0.0', true);
}
Add custom styles for the media upload popup
Add custom styles to modify the appearance of the media upload popup.
add_action('admin_print_scripts-media-upload-popup', 'add_custom_styles_for_media_popup');
function add_custom_styles_for_media_popup() {
echo '<style>
.custom-style-for-popup {
color: red;
}
</style>';
}
Trigger a JavaScript event
Trigger a custom JavaScript event when the media upload popup is loaded.
add_action('admin_print_scripts-media-upload-popup', 'trigger_custom_js_event');
function trigger_custom_js_event() {
echo '<script>
jQuery(document).ready(function($) {
$(document).trigger("custom-media-popup-loaded");
});
</script>';
}
Add a custom button to the media upload popup
Add a custom button to the media upload popup interface.
add_action('admin_print_scripts-media-upload-popup', 'add_custom_button_to_media_popup');
function add_custom_button_to_media_popup() {
echo '<script>
jQuery(document).ready(function($) {
$("#media-items").append("<button class=\'button custom-media-button\'>Custom Button</button>");
});
</script>';
}
Modify the media upload popup title
Change the title of the media upload popup.
add_action('admin_print_scripts-media-upload-popup', 'modify_media_popup_title');
function modify_media_popup_title() {
echo '<script>
jQuery(document).ready(function($) {
$("h2.media-title").text("Custom Media Upload Popup Title");
});
</script>';
}