Avatar display issue with WordPress get_avatar() function

I’m having trouble getting user avatars to show up on my WordPress site. I’ve been following the official docs, but no luck so far. Here’s what I’ve tried:

<h2>Our Team</h2>
<?php echo display_user_pic( '[email protected]', 40 ); ?>

I’ve made sure the email is in my user list and the ‘Show Avatar’ setting is on. I even tried using a user ID instead of an email, but still nothing.

When I check the page source, I see this:

<!--?php echo display_user_pic( '[email protected]', 40 ); ?-->

It looks like the PHP code is being treated as an HTML comment. Any ideas on how to fix this? I’m pretty stumped!

I’ve run into similar issues before, and it can be frustrating. From what you’ve described, it sounds like your server might not be processing PHP correctly in that particular file or location. One thing that helped me was moving the avatar code into a template part.

Try creating a new file called ‘team-member.php’ in your theme’s template-parts folder. Put your avatar code there, then include it in your main page like this:

<?php get_template_part( 'template-parts/team-member' ); ?>

This approach helped me isolate the issue and get things working. Also, double-check your theme’s functions.php file to ensure it’s not inadvertently stripping out PHP code. Some security plugins can cause this too, so it might be worth temporarily disabling them to test.

If all else fails, you could try hardcoding the Gravatar URL directly as a last resort, though that’s not ideal for maintenance.

It seems the issue might be related to how your PHP code is being processed. Based on the HTML output you’re seeing, it looks like the PHP isn’t executing at all and is instead being treated as a comment.

A few things to check:

Make sure your file has a .php extension, not .html. Verify that PHP is properly installed and configured on your server. Check if your WordPress theme is set up to process PHP in the location where you’re adding this code.

If those don’t solve it, you might want to try using WordPress’s built-in functions instead:

<?php echo get_avatar( '[email protected]', 40 ); ?>

This should work out of the box without needing a custom function. If you’re still having trouble, it might be worth checking your WordPress settings or consulting with your hosting provider to ensure PHP is running correctly.

hey there, sounds like a tricky one! have u checked if ur theme supports gravatar? sometimes themes can mess with avatar display. also, make sure ur using the right function - try get_avatar() instead of display_user_pic(). if that doesn’t work, maybe try clearing ur cache and checking for any conflicting plugins. good luck!