1

I have a multi author blog and i need show a global info message in top of add post page, so all authors can read it when they come in this specific page, how i can add it? Thank you

3 Answers 3

2

i solved with this code placed in functions.php

function my_admin_notice(){
echo '<div class="updated">
<p>message here!</p>
</div>';
}
add_action('admin_notices', 'my_admin_notice');
3
  • That will display the notice everywhere on wp-admin pages if I'm not mistaken. :)
    – Christine Cooper
    Jun 3, 2016 at 11:34
  • Yes its worked good for me, thank you for your help!
    – Stew
    Jun 4, 2016 at 20:32
  • This worked for me in 2023! I modified it slightly with echo "<pre>"; var_dump($_SERVER); echo "</pre>" in place of the message to print all server variables, but only in admin area at top. Jul 7, 2023 at 17:03
1

You can do this by hooking into the edit-post.php page. There are a variety of hooks you could use, for example, if you want to display a message below the edit title field, you could hook into edit_form_after_title.

See the example code I have below with comments:

add_action(
  'edit_form_after_title', // the hook
  'wpse_228208' // the function
);

function wpse_228208() {

  global $post;

  // confirm if the post_type is 'post'
  if ($post->post_type!== 'post')
    return;

  // you can also perform a condition for post_status, for example, if you don't want to display the message if post is already published:
  if ($post->post_status!== 'publish')
    return;

   // here goes your message
   echo '<div style="">Hello world!</div>';
}
8
  • where is edit-post.php?
    – Stew
    May 30, 2016 at 10:28
  • I was referring to the add/edit post page you're targeting. Try placing this code in your functions.php file to see it in effect.
    – Christine Cooper
    May 30, 2016 at 10:52
  • ok i add it in functions.php but Hello Word text did'nt show..thank you for all help
    – Stew
    May 30, 2016 at 11:24
  • 1
    Ok when i add you code, results is an error 500
    – Stew
    May 30, 2016 at 11:31
  • Are you sure that you have added it correctly? It should work, there are no errors in the code that I've posted. What exact error are you receiving? 500 error is not related to the code I've provided you. :)
    – Christine Cooper
    May 30, 2016 at 14:03
0

To show it above the title you can do this.

Add the following to your functions.php and make a js file of the same name in your theme directory.

function admin_js_custom() {
    $adminjs = get_stylesheet_directory_uri() . '/admin-js.js';
    echo '"<script type="text/javascript" src="'. $adminjs . '"></script>"';
}

add_action('admin_footer', 'admin_js_custom');

And then place this code in the js file.

jQuery(function($) {
    var message = "Message for the authors.";
    $('<p>' + message + '</p>').insertBefore('#titlediv')
});
6
  • It did work for me though. prntscr.com/ba4x6o Try replacing the javascript by this pastebin.com/n4xvNTww
    – Patrick S
    May 30, 2016 at 10:47
  • 1
    Why use javascript when you can output the text via PHP?
    – Christine Cooper
    May 30, 2016 at 10:51
  • Simple because the OP wanted it on "top" of the page. Your approach will also work, so given another approach to the OP in case he likes it above the title? Nothing wrong with that eh ?
    – Patrick S
    May 30, 2016 at 11:16
  • i try but show nothing Thanks anyway
    – Stew
    May 30, 2016 at 11:35
  • why dont show nothing....
    – Stew
    May 30, 2016 at 12:34

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.