1

I want to show a global message for all users in their profile page. I do not want to edit profile.php what is the hook to do this?

Basically I want to add a div to show a paragraph below the message div id <div id="message" class="updated"> and above the <form id="your-profile" novalidate="novalidate" method="post" action="http://localhost/wordpress/gantry/demo2/wp-admin/profile.php">

into this

  • How would you feel about a javascript solution? – mor7ifer Jan 27 '15 at 16:31
1

add this code to your function.php

<?php
function showMessage($message, $errormsg = false)
{
    if ($errormsg) {
        echo '<div id="message" class="error">';
    }
    else {
        echo '<div id="message" class="updated fade">';
    }
    echo "<p><strong>$message</strong></p></div>";
} 

function showAdminMessages()
{
    showMessage("This is my message.", true);
}
add_action('admin_notices', 'showAdminMessages');
?>
| improve this answer | |
  • This works well and should be the accepted answer. – jsherk Aug 17 '16 at 7:24
0

Unfortunately this is not possible, there just isn't a hook to use in wp-admin/edit-use.php.

The closest you can come is to place something under Personal Options, although this hook is called at the end of that section so this will show your message a little way down the page -

add_action('personal_options', 'my_edit_user_admin_message');
function my_edit_user_admin_message(){
?>
    <tr class="show-admin-bar user-admin-bar-front-wrap">
        <th scope="row"><label for="admin_bar_front"><?php _e( 'Admin message' )?></label></th>
        <td><fieldset>
                <legend class="screen-reader-text"><span><?php _e('Admin message') ?></span></legend>
                <label><p id="my-admin-message">This is my message.</p></label><br />
        </fieldset></td>
    </tr>
<?php
}

While not technically valid (most, but not all, browsers will correct it) you can instead use the code below, which will force your message to the top of the Personal Options section, but still under the header.

However it comes with the recommendation that you don't use it, as it's invalid to nest a block element inside a table element.

add_action('personal_options', 'my_edit_user_admin_message');
function my_edit_user_admin_message(){
?>
    <div id="my-admin-message">
        <p>This is my message.</p>
    </div>
<?php
}
| improve this answer | |
  • Although this answer may work, I think namira's answer using 'admin_notices' hook is the better choice. – jsherk Aug 17 '16 at 7:23

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.