I’ve been searching for a few hours now but I can’t seem to find a solution to this.

I’m developing a plugin and I’d like to be able to add custom text underneath the admin media library heading. I thought there might be some hook to do this.

Can’t seem to find anything that shows how you can add text to the admin screen at all. How would I go about doing this?

Thanks.

enter image description here

1 Answer
1

That area of all admin screens is where admin notices are displayed, so you could generate an admin notice.

Here’s a suitable function and hook:

function wpse_233031_admin_notice() {
    ?>
    <div class="notice notice-info">
        <p>Your message here!</p>
    </div>
    <?php
}

function wpse_233031_hook_admin_notice() {
    add_action( 'admin_notices', 'wpse_233031_admin_notice' );
}

add_action( 'load-upload.php', 'wpse_233031_hook_admin_notice' );

/* Edited out anonymous function callback, 
   which not only requires PHP 5.3 but is poor WP practice as
   it prevents removal of the function from the hook
*/

Every admin page fires a unique hook of the form load-{unique-string-for-this-screen}. For top level admin pages it takes the form load-{filename}. On the load-upload.php hook we hook into admin_notices so that your notice only appears on this screen.

You should add a class of notice to your div and one of notice-error, notice-warning, notice-success, or notice-info to get the standard WP styling. (If you add a class of is-dismissible WP will supply you with a closing icon, but I believe you need to do the heavy lifting of dismissal and storing dismissed state yourself.)

Leave a Reply

Your email address will not be published. Required fields are marked *