Halloween Sale 15% off Ends in See the plans
PHP

MemberPress: Add a Custom Tab to the Account Page

Adds a new tab, such as "Resources" or "Support", to the MemberPress account page navigation with your own content.

Don’t have WPIDE yet? Install it on your site

Code

if ( ! class_exists( 'MeprUser' ) ) {
    return;
}

$wpide_mepr_tab_slug    = 'resources';
$wpide_mepr_tab_label   = 'Resources';
$wpide_mepr_tab_content = '<h2>Member resources</h2><p>Download the latest guides and templates here.</p>';

add_action( 'mepr-account-nav', function () use ( $wpide_mepr_tab_slug, $wpide_mepr_tab_label ) {
    $active = isset( $_GET['action'] ) && $wpide_mepr_tab_slug === sanitize_key( $_GET['action'] );

    printf(
        '<span class="mepr-nav-item wpide-mepr-%1$s%2$s"><a href="%3$s"%4$s>%5$s</a></span>',
        esc_attr( $wpide_mepr_tab_slug ),
        $active ? ' mepr-active-nav-tab' : '',
        esc_url( add_query_arg( 'action', $wpide_mepr_tab_slug ) ),
        $active ? ' aria-current="page"' : '',
        esc_html( $wpide_mepr_tab_label )
    );
} );

add_action( 'mepr-account-nav-content', function ( $action ) use ( $wpide_mepr_tab_slug, $wpide_mepr_tab_content ) {
    if ( $wpide_mepr_tab_slug === $action ) {
        echo '<div class="wpide-mepr-tab">' . wp_kses_post( do_shortcode( $wpide_mepr_tab_content ) ) . '</div>';
    }
} );

Notes

Put your content in $wpide_mepr_tab_content; shortcodes are allowed.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.