Get_avatar returning empty or gravatar.com URL
-
Hi there!!
I’m developing my theme on a WordPress 4.6 platform installed on localhost using XAMPP 5.6.3.Developing my single.php page, I want the Author Avatar to be displayed. The file hierarchy is as following:
index.php -> single.php -> content.php (I’ve content types enabled and content.php is used as default template for posts. In single.php there is the loop and in content.php the content part called by get_template_part(‘content’, get_post_format);
This is the content.php code:
<article id="post-<?php the_id();?>" <?php post_class('post-single');?> > <header class="header_post"> <?php the_title(sprintf('<H1><a href="%s" rel="bookmark" class="entry-title">', esc_url( get_permalink() )), '</a></H1>'); ?> <FIGURE class="featured-image-with-text"> <?php mycustom_post_thumbnail('full','img-responsive center-block'); ?> </FIGURE> <?php the_excerpt(sprintf('<H2>', '%s', '</H2>')); ?> <div class="entry-meta-box entry-meta text-center"> <?php mycustom_author_avatar(); ?> <div class="meta-author"><span class="glyphicon glyphicon-bullhorn "></span>?<?php the_author(); ?> | <?php the_date("d/m/Y");?></div> </div> </header> <div class="limiter"></div> <div class="entry"> <?php the_content(); ?> </div> </article>
The problem is when I call the function mycustom_author_avatar. The code of the function is the following:
function mycustom_author_avatar() { //getting the ID of post/page's Author $author_id = get_the_author_meta('ID'); // sets the fallback Avatar $default = get_template_directory_uri() .'/img/logo-icon.png'; $args = array ( 'class' => 'img-circle dropshadow img-center', 'size' => 96, 'default' => $default ); echo get_avatar($author_id,$args); }
the function doesn’t show any avatar. In a early implementation it had been returning the Author ID as string. Then, looking at the HTML output I saw that the <IMG SRC> generated by get_avatr() contains a link pointing to https://1.gravatar.com/avatar/13eb0bc0c3d1b3db35b3aa996e494042?s=1&d=mm&r=g instead of the expected local avatar url or fallback image url.
Has anyone a suggestion ? I can’t really understand and figure out a solution.
Thanks
Simone
- The topic ‘Get_avatar returning empty or gravatar.com URL’ is closed to new replies.