WordPress后台定制:管理员工具条右上角显示用户姓名

前端之家收集整理的这篇文章主要介绍了WordPress后台定制:管理员工具条右上角显示用户姓名前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

91wordpress最近在使用wordpress开发一套会员在线阅读新闻系统,要求新增用户的时候填写姓和名字段,显示在右上角,会员信息如下图:

add-user

想要达到的效果如下图:

add-user-002

wordpress默认的用户功能是可以修改自己的显示名称的,这里已经删除了,现在只能通过修改代码在右上角读取用户的姓和名字段。这篇wordpress教程里我们来给大家介绍一下实现的方法

切换到主题目录,打开functions.PHP,加入以下代码

Crayon-5c891d13d86e4554901003" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-language">PHP
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-2">2
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-4">4
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-6">6
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-8">8
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-10">10
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-12">12
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-14">14
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-16">16
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-17">17
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-18">18
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-19">19
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-20">20
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-21">21
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-22">22
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-23">23
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d13d86e4554901003-24">24
Crayon-num" data-line="Crayon-5c891d13d86e4554901003-25">25
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d13d86e4554901003-1">Crayon-ta">PHPCrayon-h">
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-2">Crayon-h"> Crayon-c">//admin bar welcome info
Crayon-line" id="Crayon-5c891d13d86e4554901003-3">Crayon-h"> Crayon-e">add_actionCrayon-sy">(Crayon-h"> Crayon-s">'admin_bar_menu'Crayon-sy">,Crayon-h"> Crayon-s">'wp_admin_bar_my_custom_account_menu'Crayon-sy">,Crayon-h"> Crayon-cn">11Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-4">
Crayon-line" id="Crayon-5c891d13d86e4554901003-5">Crayon-h"> Crayon-t">functionCrayon-h"> Crayon-e">wp_admin_bar_my_custom_account_menuCrayon-sy">(Crayon-h"> Crayon-v">$wp_admin_barCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-6">Crayon-h"> Crayon-v">$user_idCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_current_user_idCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d13d86e4554901003-7">Crayon-h"> Crayon-v">$current_userCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">wp_get_current_userCrayon-sy">(Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-8">Crayon-h"> Crayon-v">$profile_urlCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_edit_profile_urlCrayon-sy">(Crayon-h"> Crayon-v">$user_idCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d13d86e4554901003-9">Crayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-h"> Crayon-cn">0Crayon-h"> Crayon-o">!=Crayon-h"> Crayon-v">$user_idCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-10">Crayon-h"> Crayon-v">$avatarCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">get_avatarCrayon-sy">(Crayon-h"> Crayon-v">$user_idCrayon-sy">,Crayon-h"> Crayon-cn">28Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d13d86e4554901003-11">Crayon-h"> Crayon-v">$howdyCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">sprintfCrayon-sy">(Crayon-h"> Crayon-e">__Crayon-sy">(Crayon-s">'Welcome,%1$s'Crayon-sy">)Crayon-sy">,Crayon-h"> Crayon-v">$current_userCrayon-i">last_nameCrayon-sy">.Crayon-s">' 'Crayon-sy">.Crayon-v">$current_userCrayon-i">first_nameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-12">Crayon-h"> Crayon-v">$classCrayon-h"> Crayon-o">=Crayon-h"> Crayon-k ">emptyCrayon-sy">(Crayon-h"> Crayon-v">$avatarCrayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">?Crayon-h"> Crayon-s">''Crayon-h"> Crayon-o">:Crayon-h"> Crayon-s">'with-avatar'Crayon-sy">;
Crayon-line" id="Crayon-5c891d13d86e4554901003-13">
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-14">Crayon-h"> Crayon-v">$wp_admin_barCrayon-e">add_menuCrayon-sy">(Crayon-h"> Crayon-t">arrayCrayon-sy">(
Crayon-line" id="Crayon-5c891d13d86e4554901003-15">Crayon-h"> Crayon-s">'id'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'my-account'Crayon-sy">,
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-16">Crayon-h"> Crayon-s">'parent'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-s">'top-secondary'Crayon-sy">,
Crayon-line" id="Crayon-5c891d13d86e4554901003-17">Crayon-h"> Crayon-s">'title'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$howdyCrayon-h"> Crayon-sy">.Crayon-h"> Crayon-v">$avatarCrayon-sy">,
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-18">Crayon-h"> Crayon-s">'href'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$profile_urlCrayon-sy">,
Crayon-line" id="Crayon-5c891d13d86e4554901003-19">Crayon-h"> Crayon-s">'Meta'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-t">arrayCrayon-sy">(
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-20">Crayon-h"> Crayon-s">'class'Crayon-h"> Crayon-o">=Crayon-h"> Crayon-v">$classCrayon-sy">,
Crayon-line" id="Crayon-5c891d13d86e4554901003-21">Crayon-h"> Crayon-sy">)Crayon-sy">,
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-22">Crayon-h"> Crayon-sy">)Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d13d86e4554901003-23">Crayon-h"> Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d13d86e4554901003-24">Crayon-h"> Crayon-sy">}
Crayon-line" id="Crayon-5c891d13d86e4554901003-25">@H_536_301@

原文链接:https://www.f2er.com/wordpress/238450.html

猜你在找的wordpress相关文章