Write notes in posts which only admins can see

If you’re the only admin, making a decision can be an easy task. You have to decide what the best for your site is and then you have to make necessary changes. But if you are running a much bigger site which requires multiple admins, you will have to cooperate with others in order to make everything work.

While you will probably have some sort of meetings where you will discuss pretty much everything about the site with other administrators, sometimes there are smaller changes about posts and pages which don’t need extra attention, making the calls or sending private messages.

In that case, leaving a note would be simply enough. But you can’t write a message for your fellow admin in the post/page itself and make it readable to everyone. That’s why you need a note which can be accessible only to admins; in this article, we will show you how to achieve that.

The following function will create a shortcode and check if a current user is an admin and if he is logged in. If so, the message between the shortcode marks will be shown, while all the other users won’t even know there’s a hidden message somewhere on the page.

Create a note shortcode:

  1. Open functions.php file
  2. Copy and paste the function and create a shortcode:
  3. function adminnote($atts, $content = NULL){
    if(current_user_can('edit_themes') || is_user_logged_in()){
    return '</pre>
    <div style="margin-bottom: 20px; font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 16px; font-weight: inherit; overflow-x: auto; white-space: -o-pre-wrap; width: 99%; word-wrap: break-word; background: #f3f3f7; border: 1px solid #dedee3; padding: 11px; line-height: 1.3em;"><b>Admin Notice</b>
    ' . $content . '</div>
    <pre>
    ';
    }
    }
    add_shortcode('note', 'adminnote');
  4. Modify Div style if you want to
  5. Save changes

After you have made the changes, you can use the [note] shortcode anywhere on the site to leave a message for admins. For example, you might want to point out that a link isn’t working or that alignment for a certain part of the post isn’t right. Instead of explaining that to other admin, you can leave a message right next to that link or a paragraph directly in the post:

[note] Check out the broken link. [/note]
[note] The second paragraph isn’t aligned as it should have been. [/note]

Again, what makes the function such a handy tool is the fact that is only visible to you and the other admins. Reading a post or finding a note in the footer will take the attention of your fellow admins while everyone else can still enjoy your site without any interruptions.

You can make the shortcode even more accessible by placing it into a button so that you can insert it into a post with a single click.

If there are bigger problems that should be taken care of, see how to quickly put a site in a maintenance mode or find one of the best maintenance plugins for WordPress.

Similarly, you can show part of the content only for logged in users or only for guests.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *