I want to use javascript to add a notice to the top of the wordpress page just like they do when auto-saving the page. But in looking at the DOM, I don't see any special div that I could find to add my notice to:


<div class="wrap">
    <h2>Edit Page <a href="http://my-site.com/wp-admin/post-new.php?post_type=page" class="add-new-h2">Add New</a></h2>
    <div style="display: block;" id="local-storage-notice" class="hidden updated">
        <p class="local-restore">
            The backup of this post in your browser is different from the version below. <a class="restore-backup" href="#">Restore the backup.</a>
        <p class="undo-restore hidden">
            Post restored successfully.     <a class="undo-restore-backup" href="#">Undo.</a>

Is there a javascript function wordpress has that I can use?


Look at F:\sites\wp-git\wp-admin\js\common.js:

$('div.updated, div.error').not('.below-h2, .inline').insertAfter( $('div.wrap h2:first') );

If your notice has the class updated or error, it will be set after the first h2 automatically. When you create custom messages, make sure you are using one of these classes. Then you can just append them to body, and WordPress will move them to the proper place.

  • Thanks. Do you know if those classes and divs have been there since 3.0? I don't want to rely on anything that's not documented and could change. – Don Rhummy Apr 22 '14 at 5:18
  • 2
    @DonRhummy They are very old, and they will probably not change, because that would break too many plugins. – fuxia Apr 22 '14 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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