Viewing 6 replies - 1 through 6 (of 6 total)
  • You can try adding this to the functions.php file in your theme. What this does is check if you have a featured image (giving you the ability to still set a custom image if you wish), then if it doesn’t find one it’ll show your avatar. Change 96 to whatever size you want to use.

    function avatar_or_featured_image($html, $post_id){
      if(has_post_thumbnail($post_id)){
        return $html;
      } else {
        return get_wp_user_avatar(get_the_author_meta('ID'), 96);
      }
    }
    add_filter('post_thumbnail_html', 'avatar_or_featured_image', 10, 2);

    If it’s not showing up, check in your template if the featured image is in a conditional like this:

    <?php if ( has_post_thumbnail() ) : ?>
        <?php the_post_thumbnail(); ?>
    <?php endif; ?>

    If it is, change it so it’s only:

    <?php the_post_thumbnail(); ?>

    Thread Starter Trebord

    (@trebord)

    Thank you very much Bangbay! I really appreciate your help with this – truly going above & beyond!

    I placed your code in my functions.php file; no result ensued; searched through my theme’s php files for the conditional; found just one instance, which I changed, but it resulted only in the avatar appearing in the Featured Image column of my (back-end) All Posts listing page . . . but not on the individual Edit Post page, and not grabbed for any front-end display.

    I’ve obviously missed another instance of that conditional . . . and presumably different themes put it in different locations (I’m using Pagelines framework) – but any ideas where I might find it?

    Thank you in advance! This is really into ‘customization’ territory, I know – Though it really ought to be a build-in WP feature/option!

    I took a look at the Pagelines theme. In includes/class.posts.php there’s a function called pagelines_show_thumb. Comment out or delete the conditional wrapper and it should work. It’s these two lines:

    if( function_exists('the_post_thumbnail') && has_post_thumbnail($post) ){

    and

    } else return false;

    Keep in mind that if you update this theme in the future that your modifications will be overwritten.

    Thread Starter Trebord

    (@trebord)

    That works!!!

    Actually, it strangely resulted also in a couple of duplicate images being placed up in the copy-pad div, but those were easily erased with CSS, so no biggie πŸ˜‰

    Thank you very much!!! A+++++++ developer support! I really do appreciate your help! (And thanks for that over-writing warning, too.)

    Gotta learn me some php one of these days…

    Hello,

    I have added the following code to functions.php

    function avatar_or_featured_image($html, $post_id){
      if(has_post_thumbnail($post_id)){
        return $html;
      } else {
        return get_wp_user_avatar(get_the_author_meta('ID'), 96);
      }
    }
    add_filter('post_thumbnail_html', 'avatar_or_featured_image', 10, 2);

    And I have removed the following conditional tags from loop.php:

    <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
    		<?php endif; ?>

    I’m unable to get the above code to have the user avatar as the post thumbnail. I’m using “Sahifa” theme by Themeforest. Please help!

    @aakarshnarula – Please start a new topic.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Avatar as Featured Image?’ is closed to new replies.