WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add special link visible to subscribers (5 posts)

  1. Harrison O.
    Member
    Posted 2 years ago #

    How can I add an admin panel visible to subscribers only so they can click and go to a special page on the front end?
    Right now I have the dashboard hidden for them and just the profile showing. I would like to have this extra panel so they can easily go to a help page.

    It doesn't need to be a menu panel though. Any link that I can add to the top of the profile page would also help.

    Any help is very much appreciated.
    Thanks in advance!

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this in your theme's functions.php for the link on top of the profile page:

    global $pagenow;
    
    if(is_admin() && $pagenow == 'profile.php' && current_user_can('subscriber')) {
    add_action( 'all_admin_notices', 'my_show_extra_profile_link' );
    }
    
    function my_show_extra_profile_link( $user ) {
    echo '<a href="mylink here">my link here</a>';
    }

    For it to show up at the bottom of the profile page use something like this:

    if(is_admin() && current_user_can('subscriber')) {
    add_action( 'show_user_profile', 'my_show_extra_profile_link' );
    }
    function my_show_extra_profile_link( $user ) {
    echo '<a href="mylink here">my link here</a>';
    }
  3. Harrison O.
    Member
    Posted 2 years ago #

    keesiemeijer,
    Thank you so much!
    It worked like a charm!!!

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    You're welcome. Glad you got it resolved.

  5. Tahir Yasin
    Member
    Posted 2 years ago #

    Hope this will make your life easier, enjoy :)

    if(is_admin()) {
        add_action('admin_menu', 'my_menu');
    }
    
    function my_menu() {
        add_menu_page('My Page Title', 'My Menu Title', 'subscriber', 'my-page-slug', 'my_function');
    }
    
    function my_function() {
        echo 'Hello world!';
    }

Topic Closed

This topic has been closed to new replies.

About this Topic