Using WordPress ‘pre-html-upload-ui’ PHP action

The pre-html-upload-ui WordPress PHP action fires before the upload button is displayed in the media upload interface.


add_action('pre-html-upload-ui', 'your_custom_function_name');
function your_custom_function_name() {
    // your custom code here


  • None

More information

See WordPress Developer Resources: pre-html-upload-ui


Display a message before the upload button

Add a custom message before the upload button to inform users about upload requirements or restrictions.

add_action('pre-html-upload-ui', 'display_custom_message');
function display_custom_message() {
    echo '<p><strong>Note:</strong> Maximum upload file size is 2 MB.</p>';

Add custom styles

Inject custom CSS to style the media upload interface.

add_action('pre-html-upload-ui', 'add_custom_styles');
function add_custom_styles() {
    echo '<style>.upload-ui { background-color: #f9f9f9; }</style>';

Add an extra upload button

Add an additional upload button for a specific purpose, such as bulk image uploading.

add_action('pre-html-upload-ui', 'add_extra_upload_button');
function add_extra_upload_button() {
    echo '<button class="button button-primary extra-upload-btn">Upload Bulk Images</button>';

Display a custom image

Show a custom image, like a logo or an infographic, before the upload button.

add_action('pre-html-upload-ui', 'display_custom_image');
function display_custom_image() {
    echo '<img src="" alt="Logo" />';

Add a custom disclaimer

Include a disclaimer or terms of service agreement before the upload button.

add_action('pre-html-upload-ui', 'add_custom_disclaimer');
function add_custom_disclaimer() {
    echo '<p>By uploading, you agree to our <a href="" target="_blank">Terms of Service</a>.</p>';