{"id":2245,"date":"2018-01-09T17:08:59","date_gmt":"2018-01-09T17:08:59","guid":{"rendered":"http:\/\/www.websitedesignwebsitedevelopment.com\/?p=2245"},"modified":"2018-01-09T17:08:59","modified_gmt":"2018-01-09T17:08:59","slug":"use-acf-image-field-wordpress-user-profile-avatar","status":"publish","type":"post","link":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/","title":{"rendered":"How to use ACF Image field as WordPress user profile avatar?"},"content":{"rendered":"<h2>How to use ACF Image field as WordPress user profile avatar?<\/h2>\n<p><code>add_filter('get_avatar', 'lb_acf_profile_avatar', 10, 5);<br \/>\nfunction lb_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) {<br \/>\n$field_name = 'lb_local_avatar';<br \/>\n$user = '';<br \/>\n\/\/ Get user by id or email<br \/>\nif ( is_numeric( $id_or_email ) ) {<br \/>\n$id = (int) $id_or_email;<br \/>\n$user = get_user_by( 'id' , $id );<br \/>\n} elseif ( is_object( $id_or_email ) ) {<br \/>\nif ( ! empty( $id_or_email-&gt;user_id ) ) {<br \/>\n$id = (int) $id_or_email-&gt;user_id;<br \/>\n$user = get_user_by( 'id' , $id );<br \/>\n}<br \/>\n} else {<br \/>\n$user = get_user_by( 'email', $id_or_email );<br \/>\n}<br \/>\nif ( ! $user ) {<br \/>\nreturn $avatar;<br \/>\n}<br \/>\n\/\/ Get the user id<br \/>\n$user_id = $user-&gt;ID;<br \/>\n\/\/ Get the file id<br \/>\n$image_id = get_user_meta($user_id, $field_name, true);<br \/>\n\/\/ Bail if we don't have a local avatar<br \/>\nif ( ! $image_id ) {<br \/>\nreturn $avatar;<br \/>\n}<br \/>\n\/\/ Get the file size<br \/>\n$image_url = wp_get_attachment_image_src( $image_id, 'thumbnail' ); \/\/ Set image size by name<br \/>\n\/\/ Get the file url<br \/>\n$avatar_url = $image_url[0];<br \/>\n\/\/ Get the img markup<br \/>\n$avatar = '&lt;img alt=\"' . $alt . '\" src=\"' . $avatar_url . '\" class=\"avatar avatar-' . $size . '\" height=\"' . $size . '\" width=\"' . $size . '\"\/&gt;';<br \/>\n\/\/ Return our new avatar<br \/>\nreturn $avatar;<br \/>\n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to use ACF Image field as WordPress user profile avatar? add_filter(&#8216;get_avatar&#8217;, &#8216;lb_acf_profile_avatar&#8217;, 10, 5); function lb_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) { $field_name = &#8216;lb_local_avatar&#8217;; $user = &#8221;; \/\/ Get user by id or email if ( is_numeric( $id_or_email ) ) { $id = (int) $id_or_email; $user = get_user_by( &#8216;id&#8217; , $id ); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[12],"tags":[],"class_list":["post-2245","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to use ACF Image field as WordPress user profile avatar? - AndroidBubble Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use ACF Image field as WordPress user profile avatar? - AndroidBubble Blog\" \/>\n<meta property=\"og:description\" content=\"How to use ACF Image field as WordPress user profile avatar? add_filter(&#039;get_avatar&#039;, &#039;lb_acf_profile_avatar&#039;, 10, 5); function lb_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) { $field_name = &#039;lb_local_avatar&#039;; $user = &#039;&#039;; \/\/ Get user by id or email if ( is_numeric( $id_or_email ) ) { $id = (int) $id_or_email; $user = get_user_by( &#039;id&#039; , $id ); [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\" \/>\n<meta property=\"og:site_name\" content=\"AndroidBubble Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-09T17:08:59+00:00\" \/>\n<meta name=\"author\" content=\"Fahad\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fahad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\"},\"author\":{\"name\":\"Fahad\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"headline\":\"How to use ACF Image field as WordPress user profile avatar?\",\"datePublished\":\"2018-01-09T17:08:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\"},\"wordCount\":22,\"articleSection\":[\"Wordpress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\",\"url\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\",\"name\":\"How to use ACF Image field as WordPress user profile avatar? - AndroidBubble Blog\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\"},\"datePublished\":\"2018-01-09T17:08:59+00:00\",\"author\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"breadcrumb\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/androidbubble.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Website Development\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Frameworks\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Wordpress\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to use ACF Image field as WordPress user profile avatar?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\",\"url\":\"https:\/\/androidbubble.com\/blog\/\",\"name\":\"AndroidBubble Blog\",\"description\":\"Articles &amp; Posts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/androidbubble.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\",\"name\":\"Fahad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"caption\":\"Fahad\"},\"sameAs\":[\"http:\/\/www.androidbubbles.com\/\",\"https:\/\/x.com\/phpFlex\"],\"url\":\"https:\/\/androidbubble.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use ACF Image field as WordPress user profile avatar? - AndroidBubble Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/","og_locale":"en_US","og_type":"article","og_title":"How to use ACF Image field as WordPress user profile avatar? - AndroidBubble Blog","og_description":"How to use ACF Image field as WordPress user profile avatar? add_filter('get_avatar', 'lb_acf_profile_avatar', 10, 5); function lb_acf_profile_avatar( $avatar, $id_or_email, $size, $default, $alt ) { $field_name = 'lb_local_avatar'; $user = ''; \/\/ Get user by id or email if ( is_numeric( $id_or_email ) ) { $id = (int) $id_or_email; $user = get_user_by( 'id' , $id ); [&hellip;]","og_url":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/","og_site_name":"AndroidBubble Blog","article_publisher":"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453","article_published_time":"2018-01-09T17:08:59+00:00","author":"Fahad","twitter_misc":{"Written by":"Fahad","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/#article","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/"},"author":{"name":"Fahad","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"headline":"How to use ACF Image field as WordPress user profile avatar?","datePublished":"2018-01-09T17:08:59+00:00","mainEntityOfPage":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/"},"wordCount":22,"articleSection":["Wordpress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/","url":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/","name":"How to use ACF Image field as WordPress user profile avatar? - AndroidBubble Blog","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/#website"},"datePublished":"2018-01-09T17:08:59+00:00","author":{"@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"breadcrumb":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/androidbubble.com\/blog\/website-development\/php-frameworks\/wordpress\/use-acf-image-field-wordpress-user-profile-avatar\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/androidbubble.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Website Development","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/"},{"@type":"ListItem","position":3,"name":"PHP Frameworks","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/"},{"@type":"ListItem","position":4,"name":"Wordpress","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/php-frameworks\/wordpress\/"},{"@type":"ListItem","position":5,"name":"How to use ACF Image field as WordPress user profile avatar?"}]},{"@type":"WebSite","@id":"https:\/\/androidbubble.com\/blog\/#website","url":"https:\/\/androidbubble.com\/blog\/","name":"AndroidBubble Blog","description":"Articles &amp; Posts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/androidbubble.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7","name":"Fahad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","caption":"Fahad"},"sameAs":["http:\/\/www.androidbubbles.com\/","https:\/\/x.com\/phpFlex"],"url":"https:\/\/androidbubble.com\/blog\/author\/admin\/"}]}},"views":762,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/2245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/comments?post=2245"}],"version-history":[{"count":1,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/2245\/revisions"}],"predecessor-version":[{"id":2246,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/2245\/revisions\/2246"}],"wp:attachment":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/media?parent=2245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/categories?post=2245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/tags?post=2245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}