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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.