Add A New Tab On My Account Page

A- A+

You have to first  add your template file first on the,

/wp-content/themes/twentytwenty-child/wpuf/my-page.php or /wp-content/plugins/wp-user-frontend/templates/my-page.php to load the template section on the My Account page.

Then add this following code on the theme/child-theme’s functions.php file.

/*
* Add custom section/menu (My Page) on the My Account page
*/
add_filter( 'wpuf_account_sections', 'wpuf_my_page' );

function wpuf_my_page( $sections ) {
$sections = array_merge( $sections, array( array( 'slug' => 'my-page', 'label' => 'My Page' ) ) );

return $sections;
}

add_action( 'wpuf_account_content_my-page', 'wpuf_my_page_section', 10, 2 );

function wpuf_my_page_section( $sections, $current_section ) {
wpuf_load_template(
"my-page.php",
array( 'sections' => $sections, 'current_section' => $current_section )
);
}

We have added a new shortcode to show all the user data on one page. The short code [[wpuf_account]] adds helpful information on the same page and organizes them in tabs.

If you want to add your own page on the tab, you can use the filter wpuf_account_sections. It works based on page slugs.

Adding your own page

If you want to add a page that has the slug `your-score`, then you have to replace the following line of code accordingly.

[php]
$sections = array_merge( $sections, array( array( 'slug' => 'your-score', 'label' => 'Scoreboard' ) ) );
[/php]

Use the above PHP code to functions.php file in your child theme.

Now you have to change the action and function accordingly. So the action would look like this:

[php]
add_action( 'wpuf_account_content_your-score', 'wpuf_your_score_section', 10, 2 );

function wpuf_your_score_section( $sections, $current_section ) {
wpuf_load_template(
"my-page.php",
array( 'sections' => $sections, 'current_section' => $current_section )
);
}
[/php]

The digits in the following code:

[php] add_action ( 'wpuf_account_content_my-page', 'wpuf_my_page_section', 10, 2 ); [/php]

represent the order and priority respectively. So depending on the number, the tab orders can be changed. It is to be noted that you can override default templates or load any custom template. To override a built-in template follow the instructions in How To Override Templates. In order to create a custom template, follow the same instructions as overriding templates and add the template filename to following line of code. For example if we add a custom template as “my-page.php” then our code will look like following

[php]
wpuf_load_template(
"my-page.php",
array( 'sections' => $sections, 'current_section' => $current_section )
);
[/php]

Example

[php]
add_filter( 'wpuf_account_sections', 'wpuf_my_page' );

function wpuf_my_page( $sections ) {
$sections = array_merge( $sections, array( array( 'slug' => 'my-page', 'label' => '<strong>My Page</strong>' ) ) );

return $sections;
}

add_action( 'wpuf_account_content_my-page', 'wpuf_my_page_section', 10, 2 );

function wpuf_my_page_section( $sections, $current_section ) {
wpuf_load_template(
"my-page.php",
array( 'sections' => $sections, 'current_section' => $current_section )
);
}
[/php]

*** You can change the label “My Page” to whatever label you want.