0

I have a working plug-in, but to add a little polish I would like to add the plug-in title to the h1 block at the top of the wrap container, but ahead of the admin_notices list, in the same way that most Wordpress admin pages have. I am sure this is quite easy but without knowing the name it is very hard to find where I can configure this and I can't think of any distinguishing search terms. The in_admin_header action is almost in the right place but it is a little early (ahead of the wrap container) and obviously that runs on every page. The next event on the list is admin_notices which is too late. Also this is such a standard thing I feel like it should have a really basic hook somewhere, that I've just managed to miss.

What do I need to do to give my plugin a standard headline title?

1 Answer 1

2

You shouldn't need to hook anywhere in particular, simply output your heading at the start of your settings page callback and WP should position admin notices appropriately after your heading (there's some logic written into the js/jquery).

For example i have lines like this at the start of various plugin settings pages.

<div class="wrap">      
    <h1><?php _e( 'My Plugin Name', 'my_text_domain' ); ?></h1>
    <?php settings_errors(); ?>

Some have additional or other markup, but the admin notices, whether they are Settings saved or error notices will render after the heading if it's inside a wrap element, <div class="wrap"> in my above sample. You could move the <?php settings_errors(); ?> portion of my code above before the heading and WP would move the notice when it's rendered.

I can't recall off the top of my head where this is done in the core js, but i'll have a dig and edit that info into this answer.

Later edit:

The WP admin javascript common.js sets up where notices are produced, here's a link to the portion of code in core.

wp-admin/js/common.js

2
  • 1
    Oh, wow, it only works if I include the wrap div in my plug-in. I assumed I shouldn't do that because Wordpress added that div anyway and it would be weird to have it twice, but apparently if I add that, my plug-in changes the structure of the page and sits where I want it to.
    – glenatron
    Commented Nov 4, 2022 at 13:17
  • 1
    Updated my answer and linked to the source code so you can see where and how this is done.
    – t31os
    Commented Nov 4, 2022 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.