Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Last active February 29, 2024 02:27
Show Gist options
  • Save cartpauj/9c93e4929040d72a248c9387cba1a6e7 to your computer and use it in GitHub Desktop.
Save cartpauj/9c93e4929040d72a248c9387cba1a6e7 to your computer and use it in GitHub Desktop.
Shortcode to show MemberPress Account page navigation menu on any page
<?php
//
// PASTE SHORTCODE [mepr-account-nav-menu] after adding this snippet to your site
// Use Code Snippets plugin (run snippet only on front end)
// https://wordpress.org/plugins/code-snippets/
//
function mepr_show_nav_menu() {
if(!class_exists('MeprAccountCtrl')) { return; }
$mepr_options = MeprOptions::fetch();
$_REQUEST['action'] = 'mepr-fake';
$old_uri = $_SERVER['REQUEST_URI'];
$parsed = parse_url($mepr_options->account_page_url());
$_SERVER['REQUEST_URI'] = $parsed['path'];
// Should show just the nav - this tricks MP into thinking there's content to display
add_action('mepr_account_nav_content', function($action) {
echo ' ';
});
ob_start();
?>
<style type="text/css">
body .mp_wrapper div.mepr_error {
display:none !important;
}
div#mepr-account-nav {
margin-bottom:25px;
width: auto !important;
}
.mepr-nav-item {
padding: 0 10px 0 0;
}
</style>
<?php
$ctrl = new MeprAccountCtrl();
$ctrl->render(); // Render account page
$_SERVER['REQUEST_URI'] = $old_uri;
return ob_get_clean();
}
add_shortcode('mepr-account-nav-menu', 'mepr_show_nav_menu');
@vdiddy95
Copy link

Do you have any CSS snippets available to make the navigation look like the default navigation instead of just exposed links?

This is what I need it to look like.
(https://user-images.githubusercontent.com/136761720/246265575-b7c6c795-c784-4198-b1a9-dbc4eff56883.jpeg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment