Récemment, nous vous avons affiché comment styliser la mise en page de vos commentaires et comment styliser votre formulaire de commentaires. L’une de nos utilisateurs/utilisatrices nous a envoyé un e-mail pour nous demander « comment avez-vous fait pour que les images de vos gravatars soient rondes ? Est-ce que vous stockez les images gravatar localement pour qu’elles soient rondes ? « . Dans cet article, nous allons vous montrer comment afficher des images gravatar rondes dans WordPress. Nous utiliserons la propriété border-radius de CSS3 pour créer des images gravatar circulaires.
La première chose à faire est de modifier le fichier style.css de votre thème. Vous pouvez le faire en utilisant un programme FTP ou en allant dans Apparence » Éditeurs/éditrices dans l’administration de WordPress. Ensuite, vous voulez ajouter le code suivant dans votre fichier CSS :
.avatar { border-radius: 50%; -moz-border-radius: 50%; -webkit-border-radius: 50%; }
Cela devrait fonctionner sur la plupart des thèmes WordPress. Cependant, si cela ne fonctionne pas sur votre thème, alors il y a probablement une extension ou une fonction de votre thème qui perturbe les classes par défaut utilisées pour gravatar dans WordPress. Afin de trouver quelle classe CSS les images gravatar utilisent dans votre thème, vous devez ouvrir une publication de blog qui a des commentaires. Sélectionné jusqu’à la section des commentaires, cliquez avec le bouton droit de la souris sur l’image gravatar pour sélectionner Inspecter l’élément. Cela vous affichera le code source de votre gravatar, comme ceci :
Si l’image gravatar a quelque chose d’autre qu’avatar, utilisez-le à la place de .avatar dans le code CSS ci-dessus.
Nous espérons que cet article vous a aidé à afficher des images gravatar rondes sur votre blog WordPress. Faites-nous savoir si vous avez des questions ou des retours en laissant un commentaire ci-dessous.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Rex says
Very timely. Thank you so much.
WPBeginner Support says
You’re welcome
Administrateur
pujara says
How to add comment image automatically like in your comment system?
Nataly says
hello, It worked, thank you, but, the description appear to high. over the pic, do you know to make it appear at the side of the pic?
Therese says
I can’t make it work.
I can’t figure out where exactly to put it, nothing seams to change. I’ve looked at the source code and it’s got avatar just like the example source code.
WPBeginner Support says
Did you add the CSS in your theme’s stylesheet?
Administrateur
ERFmama says
Yes I did. I have the Twenty Twelve theme.
Is there a specific place it has to go? In the style.css
Edit: Never mind it suddenly worked now!
Can I ask how to change the size of the avatars please? Or have you already written that down somewhere?
Thank you so much for this!
Daniel says
It worked, thank you
Chrissy says
Fantastic! Exactly what I was looking for! Thanks you guys rock!
Jacky says
THANK YOU so much for this, spent hours trying to accomplish. You provided the most straightforward solution!
Abdul Samad says
Bro Thanks For This Code I’m New In WP and I really Enjoying Your Blog Man Thanks For THis And All Tutorials ….
Richie says
I was going to pass along this tip and of course tried it first on one of my sites.
Worked like a champ I simply changed my CSS from px to % for the border moz and webkit.
Here’s where it got interesting.
I went to another site, did the same tweak and it didn’t work. After a little head scratching I remembered that I had the plugin WP User Avatar installed on the site that it worked on and didn’t have it installed on the site it didn’t work on.
I installed the plugin and whalah, works like a champ.
For both sites I’m using a custom theme built on the Presswork framework.
Bottom line, I got it to work but only with the plugin.
Any ideas?
Editorial Staff says
It is possible that your theme wasn’t using the css class .avatar, and the plugin added that.
Administrateur
Richie says
I’ll check it out. Thanks
Roselle Celina says
Hi there, thanks for this tutorial! It’s working great on chrome and Firefox, but for Safari, I’m getting this same problem: http://jsfiddle.net/2UT8v/2/
Thanks in advance for your help
Editorial Staff says
It seems that the border width is where the issue seems to be in safari.
Administrateur
RW says
I agree and I only use IE about 4% of the time but several of my customers are still on 8.
Thanks,
Bob
Martin says
If somebody uses IE8 does not deserve for round image
RW says
Great tip. Please note that IE8 doesn’t natively render round corners (border-radius). You’d need to use javascript, pie, etc… for this but not worth the trouble. Luckily IE9 recognizes current standards…
Thanks.
Jim Burnett says
I remember the days we were trying to keep IE6 support in the loop. Not it’s IE 8 for rounded corners. Lucky us, IE9 is picking up.
Then again, FF 3.0 doesn’t support any HTML 5. *sad face*
Cool CSS trick though!