In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to achieve the PHP script used to obtain and customize profile pictures in WordPress. It is very detailed and has a certain reference value. Interested friends must finish reading it!
Get_avatar () (get avatar)
The get_avatar () function is used to get the top mailbox or the user's avatar code, which is not often used in the comment list.
This function provides a get_avatar filter to filter the Html code (img tag) of the avatar.
If the display avatar option is turned off in the discussion in the background Settings, then return False.
Usage
Get_avatar ($id_or_email, $size, $default, $alt)
Parameters.
$id_or_email
(integer | string | object) (required) user's ID; mailbox; comment or user's object. If you are in a loop, you can use the get_the_author_meta ('ID') function to call the author of the current article.
Default value: None
$size
(integer) (optional) the size of the avatar, up to 512 in pixels (px).
Default value: 96
Get_avatar () (get avatar)
$default
(string) (optional) if there is no picture returned by the avatar, the default is "Secret Man", which can be the picture URL.
Default value: empty string (mystery man)
$alt
(string) (optional) the alt attribute content of the avatar img tag.
Default value: False
Return value
(string | Boolean) returns the img tag of an avatar, and returns False if the display avatar option is turned off in the discussion of Settings in the background.
Examples
List of comments:
Loop to get the profile picture of the author of the current article:
Custom mailbox:
Customize the alt tag of the avatar picture
WordPress uses Gravatar avatar by default, which is called by the get_avatar () function and is generally used when calling comments.
You can set the alt tag of the return code with $alt, the fourth attribute of the get_avatar () function, but most people don't set it when using it, so it becomes blank.
Search engine crawlers can not read what is on the picture, only rely on its alt tag, without the alt tag of the picture, is very bad for SEO.
If you want to uniformly tag all avatars with an alt tag, you can put the following code in the theme's functions.php file.
/ * * alt tags for WordPress custom avatars * make different alt tags according to different lives * http://www.endskin.com/avatar-alt/*/function Bing_avatar_alt ($avatar) {$alt=' Gravatar avatar'; / / contents of the alt tag $before = strpos ($avatar, "alt='"); $after = strpos ($avatar, "'", $before); if ($before = = false | | $after = = false) return $avatar; $alt= esc_attr ($alt) Return substr ($avatar, 0, $before). "alt='$alt". Substr ($avatar, $after + strlen ("'"));} add_filter ('get_avatar',' Bing_avatar_alt')
This is fine, pay attention to change the $alt variable in the code to the content of the alt tag you want to modify.
Make different alt tags according to different lives
If you want to place different alt tags according to different people, you can use the following example code:
/ * alt tag of WordPress custom avatar image * http://www.endskin.com/avatar-alt/*/function Bing_avatar_alt ($avatar, $id_or_email) {if ($id_or_email = = 'bingoblog@163.com' | | $id_or_email = 1) {$alt =' blogger Gravatar avatar'; / / blogger's alt tag content} else {$alt = 'Gravatar avatar' / / normal visitor's alt tag content} $before = strpos ($avatar, "alt='"); $after = strpos ($avatar, "'", $before); if ($before = false | | $after = false) return $avatar; $alt= esc_attr ($alt); return substr ($avatar, 0, $before). "alt='$alt". Substr ($avatar, $after + strlen ("'"));} add_filter ('get_avatar',' Bing_avatar_alt', 10,2)
Do not replace if the alt tag is already set
If you need to set the content of the alt tag (the $alt attribute of the get_avatar () function), you can use the following code if you don't replace it:
/ * * the alt tag of WordPress custom avatar image * do not replace * http://www.endskin.com/avatar-alt/*/function Bing_avatar_alt ($avatar, $id_or_email, $size, $default, $alt) {if (! empty ($alt)) return $avatar; $alt=' Gravatar avatar'; / / the content of the alt tag $before = strpos ($avatar, "alt='") $after = strpos ($avatar, "'", $before); if ($before = false | | $after = = false) return $avatar; $alt = esc_attr ($alt); return substr ($avatar, 0, $before). "alt='$alt". Substr ($avatar, $after + strlen ("'"));} add_filter ('get_avatar',' Bing_avatar_alt', 10, 5). The above is all the content of the article "how to implement the PHP script for obtaining and customizing avatar images in WordPress". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.