Filter Hook – user_profile_filter_profile_navs

By default there 4 default nav’s on user profile navigation.

feed
about
followers
following

 

These navigation is filterable and actionable to display nav’s content, we used following filter hook for display navs

apply_filters('user_profile_filter_profile_navs', $navs);

 

how to add extra nav’s?

Please see the example code you can add extra navigation by filter hook

add_filter('user_profile_filter_profile_navs','user_profile_filter_profile_navs_extra_nav');
function user_profile_filter_profile_navs_extra_nav($navs){
$navs['extra_nav'] = array('title' => __('Extra nav', 'user-profile'),);
return $navs;
}

 

Display content for “extra_nav”

 add_action('user_profile_action_nav_content_extra_nav','user_profile_filter_profile_navs_extra_nav_content', 10, 2);
function user_profile_filter_profile_navs_extra_nav_content($user_id, $thisuser){
ob_start();
?>
<div class="extra-nav-html">
Extra HTML.
<br>
<?php
echo 'User id:'. $user_id;
?>
</div>
<?php
echo ob_get_clean();
}

User profile Plugin

 

How to remove existing navs

you can remove any existing nav by filter hook as follows

add_filter('user_profile_filter_profile_navs','user_profile_filter_profile_navs');
function user_profile_filter_profile_navs($navs){
unset($navs['feed']);
return $navs;
}

 

Sorting/priority of navs

You can set custom sorting or priority of navs, see the example code bellow

function user_profile_filter_profile_navs_extra($navs){
$navs['followers']['priority'] = 5;
return $navs;
}
add_filter('user_profile_filter_profile_navs', 'user_profile_filter_profile_navs_extra');

 

Change navs title

You can change nav name by filter hook as follows

function user_profile_filter_profile_navs_extra($navs){
$navs['followers']['title'] = __('Followers new', 'user-profile');
return $navs;
}
add_filter('user_profile_filter_profile_navs', 'user_profile_filter_profile_navs_extra');

user profile plugin

 

Add navs title icons

You can display icon for navs title by filter hook, please see the bellow code we are displaying font-awesome icon

function user_profile_filter_profile_navs_extra($navs){
$navs['followers']['title'] = '<i class="icofont icofont-heart"></i> '.__('Followers new', 'user-profile');
return $navs;
}
add_filter('user_profile_filter_profile_navs', 'user_profile_filter_profile_navs_extra');

 

User profile Plugin