Advertisement
marciomrb

Function

Jan 11th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. function give_profile_name($atts){
  2.     $user=wp_get_current_user();
  3.     $name=$user->user_firstname;
  4.     return $name;
  5. }
  6.  
  7. add_shortcode('profile_name', 'give_profile_name');
  8.  
  9. add_filter( 'wp_nav_menu_objects', 'my_dynamic_menu_items' );
  10. function my_dynamic_menu_items( $menu_items ) {
  11.     foreach ( $menu_items as $menu_item ) {
  12.         if ( strpos($menu_item->title, '#profile_name#') !== false) {
  13.                 $menu_item->title =  str_replace("#profile_name#",  wp_get_current_user()->billing_company, $menu_item->title);
  14.         }
  15.     }
  16.  
  17.     return $menu_items;
  18.  
  19. <!-- no campo "billing_company" você muda pra "display_name"... ou outra coisa
  20. https://codex.wordpress.org/Function_Reference/wp_get_current_user
  21.  
  22. no menu você coloca "#profile_name#" sem aspas... -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement