WebAppsGuides

A guide to tech breakthroughs

How to get user profile image URL in WordPress

ThemeCreation

webapps Lab

June 7, 2021

In this post, you will find a step-by-step process that will retrieve the user profile image URL in WordPress.

The common way to get the image uses the get_avatar function.

The function itself returns an HTML IMG tag which makes it hard to customize.

But having a profile picture link enables to set the user’s image as a background picture.

And it is simple to customize the image.

In fact, you will be able to set the image width.

WordPress function for avatar URL.

It is the get_avatar_url function that retrieves the author image URL without HTML image tags.

get_avatar_url takes the user id as an argument to return a required avatar link of the author.

The WordPress framework provides the author id using get_the_author_meta.

The code snippet

$theAuthorId = get_the_author_meta('ID');

$getUserUrl = get_avatar_url ($theAuthorId);

A function can set the image size.

The size value is defined in the array by an element with a key of ‘size’.

The array forms a second argument in the get_avatar_url function.

$getUserUrl = get_avatar_url($theAuthorId, array ('size' => 500));

Set up user profile image as a background picture

<div style = “background-image : url (‘<?php echo get_avatar_url($theAuthorId, array (‘size’ => 500));?>’)  ;”>

Comments

Your email will not be published, Red mark sections* must be filled to comment

Related Posts

No Featured Image

How to get the author role in WordPress

In WordPress, there are six basics user capabilities and roles. When the blog has many authors(users) it becomes a challenge to reveal the roles of a user. Although, it is […]

No Featured Image

Get author nickname in wordpress

WordPress allows displaying the author’s nickname instead of the real name. The actual and non-deprecated WordPress function for display is get_the_author_meta. To output the nickname, the field value of nickname […]

No Featured Image

Get Author image in WordPress without plugin

You can display the author’s images in the writer biography box which exposes the author’s social media profiles. In WordPress, there is a number of WordPress plugins that can show […]

No Featured Image

How to get author posts in wordpress

This is a short and simplified instruction to get a specific author’s posts in WordPress. If the website has at least one author, each author’s posts can be shown on […]

WebAppsGuides

A guide to tech breakthroughs

E-mail : simunzuriblog@gmail.com

Company