Home > CMS Tutorial > WordPress > Teach you how to quickly modify the existing avatar in WordPress

Teach you how to quickly modify the existing avatar in WordPress

藏色散人
Release: 2021-08-03 15:47:51
forward
4919 people have browsed it

As shown below, the WordPress default avatar customization has been successfully modified!
Teach you how to quickly modify the existing avatar in WordPress

The avatar in the above picture is not available by default. It is required. We customize it ourselves!

Friends who are familiar with WordPress should know that in the background - settings - discussion, you can set the default Gravatar avatar, but the icons that come with it are really not flattering. Fortunately, WordPress provides avatar_defaults. The hook allows us to add a custom avatar. Below, Host Select Discount Network will share 2 ways to modify it.

Method 1: Use code to customize WordPress’ default Gravatar avatar

Add the following code before the last ?> in your theme’s functions.php:

//修改默认头像
add_filter('avatar_defaults', 'default_avatar');
function default_avatar($avatar_defaults) {
$myavatar = 'https://i.loli.net/2020/07/19/idoODqFrH4XW7J5.jpg';//图文url路径
$avatar_defaults[$myavatar] = "主机精选优惠网";//图片的描述名称
return $avatar_defaults;
}
Copy after login

Modification tips:

1. The fourth line of code is the URL address of the avatar. The above is wpdaxue-gravatar.jpg under the images folder of the current theme. Please modify it according to the actual situation;

2. The fifth line is the name of the custom avatar. The above is the default avatar of WordPress University. Please modify it yourself.

After saving, you can see the new avatar in the background - Settings - Discussion, and set it as the default:

Teach you how to quickly modify the existing avatar in WordPress

Method 2: Use the Add New Default Avatar plug-in

If you don’t want to mess with the code, you can also install the Add New Default Avatar plug-in directly in the background. After enabling it, you can add a custom avatar under the background - Settings - Discussion, which is very Simple.

The above is the detailed content of Teach you how to quickly modify the existing avatar in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template