Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

THIS IS THE DIV WHERE WORDPRESS's NOTICES ARE

<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>
        <p class="undo-restore hidden">
            Post restored successfully.     <a class="undo-restore-backup" href="#">Undo.</a>
        </p>
    </div>

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

share|improve this question

1 Answer 1

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.

share|improve this answer
    
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 at 5:18
    
@DonRhummy They are very old, and they will probably not change, because that would break too many plugins. –  toscho Apr 22 at 7:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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