Sometimes you want to be able to display messages to new users or users with specific roles, such as authors or contributors. This recipe will display a message to users of the site based on their user role.
Open the index.php
file of your theme. We are going to create a message area on the home page. Paste the following code below the content div
tag and above the WordPress loop:
<?php /* * Chapter 11 Example 6 * Creates a user message area on the home page. Paste above the WordPress loop. */ function get_my_user_message() { if (is_user_logged_in() && current_user_can('level_1')){ echo "Remember we publish posts on Tuesdays, Wednesdays, and Thursdays!"; } /* closing contributer role or higher text bracket */ else if (is_user_logged_in() && current_user_can('level_0')){ echo "Let us know if you see any grammatical errors in any posts!"; } /* closing else if subscriber text */ else { /*here is a paragraph...