Adding HTML/Text to Top of Subscriber’s Profile Backend Page

After a new user creates an account and logs in, the subscriber lands at the /wp-admin/profile.php page. With certain demographics, I’ve found some users tend to get stuck there.

I’d like to be able to add HTML such as a descriptive paragraph with links to areas on the site, to the top of the Subscriber level Profile page; if possible between the ‘Profile’ header and ‘Personal Details’.

Uses for this include directing users back to applications, specific forms, etc.

Pseudo code for envisioned profile.php is:

...
<h1>Profile</h1>

if user is subscriber, then echo:

<div class="subscriberProfile">
    <p>Looking for the <a href="http://example.com/form">Example Form</a>?</p>
</div>

Thank you in advance.

1 Answer
1

Add this code to your functions.php to add a notice for users with the subscriber role on their profile and dashboard admin pages.

function wpse239290_user_welcome_notice() {
    // Make sure that the user is assigned to the subscriber role, specifically.
    // Alternatively, capabilities can be checked with current_user_can(), but roles are not supposed to be checked this way.
    $user = wp_get_current_user();
    if ( ! in_array( 'subscriber', $user->roles ) ) {
        return;
    }

    // Make sure the profile or dashboard screens are being viewed.
    $screen = get_current_screen();
    if ( ! $screen || ( 'profile' !== $screen->id && 'dashboard' !== $screen->id ) ) {
        return;
    }

    // Show a friendly green notice, and allow it to be dismissed (it will re-appear if the page is reloaded though).
    $class="notice notice-success is-dismissible";

    // Customize the HTML to  fit your preferences.
    $message="<p>Looking for the <a href="http://example.com/form">Example Form</a></p>";

    printf( '<div class="%1$s"><div class="subscriberProfile">%2$s</div></div>', $class, $message ); 
}
add_action( 'admin_notices', 'wpse239290_user_welcome_notice' );

Leave a Comment