Php 将Gravatar添加到WP标头

Php 将Gravatar添加到WP标头,php,wordpress,wordpress-theming,avatar,gravatar,Php,Wordpress,Wordpress Theming,Avatar,Gravatar,我想显示当前登录用户的gravatar,如果用户没有gravatar,它将显示默认的wp man(或使用URL的img) 这是我目前掌握的代码 <div class="gravatar"> <img src="http://techyoucation.com/wp-content/themes/blank/images/treehouse.png" alt=""/> </div> 上面的代码只是显示了一个随机图像,我想将其更改为已登录用户的gravat

我想显示当前登录用户的gravatar,如果用户没有gravatar,它将显示默认的wp man(或使用URL的img)

这是我目前掌握的代码

<div class="gravatar">
<img src="http://techyoucation.com/wp-content/themes/blank/images/treehouse.png" alt=""/> 
</div>

上面的代码只是显示了一个随机图像,我想将其更改为已登录用户的gravatar(当没有用户登录时,它将隐藏,但我会在以后进行)

那么,有人知道我需要做什么才能让它工作吗

提前谢谢

亚历德

更新

使用

<div class="logo"><a href="http://techyoucation.com"><img src="<?php
$user_id = get_current_user_id() // Get the user ID
$size_avatar = 50 // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-    content/themes/blank/images/treehouse.png' // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar );
?>" alt="techyoucation logo" width="219" height="47" id="Logo" /></a></a>

Dreamweaver说有3个语法错误?我把你的密码用错了吗

谢谢

更新

好吧,现在我有了

<div class="gravatar">
<img src="<?php
$user_id = get_current_user_id(); // Get the user ID
$size_avatar = 50; // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-content/themes/blank/images/treehouse.png'; // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar );
?>" alt=""/> 
  </div>

“alt=”“/>
但图像不显示。当我右键单击并选择“复制图像URL”时,它会给我 ''%20src=''%20class='avatar%20avatar-50%20photo%20avatar默认值'%20height='50'%20width='50'%20/%3E'

任何想法


谢谢

您只需使用wordpress可插拔功能提供的功能即可:

代码更新


请看问题。我已经更新了使用您提供的代码时会发生什么情况?感谢带有$user\u id、$size\u avatar的行有分号(;)missing@chepe263谢谢,但图像现在不显示,右键单击并选择“复制图像URL给我”“谢谢”
<div class="gravatar">
<?php
$user_id = get_current_user_id(); // Get the user ID
$size_avatar = 50; // Set the avatar size
$default_avatar = 'http://techyoucation.com/wp-content/themes/blank/images/treehouse.png'; // Set your default image url
echo get_avatar( $user_id, $size_avatar, $default_avatar ); // This prints the <img> tag with correct avatar image url
?>
</div>