I need little bit help and customization on my existng script at function.php for wordpress 3.5. Here's what I have. As you can see here the default picture is none exist will be using

 $first_img = $img_dir . '/images/post-default.jpg';

I would like to know if there would be possibility to just grab author's posts picture. Please find below the whole code related to this function. Thanks B4..

// Get Standard Post Image
function get_post_image() {
  global $post, $posts;
  $first_img = '';
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $img_dir = get_bloginfo('template_directory');
    $first_img = $img_dir . '/images/post-default.jpg';
  return $first_img;

1 Answer 1


There was a lotta junk in that function, here's all you need:

function get_post_image() {
    global $post;

    if ( preg_match( '/<img.+?src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches ) )
        $image = $matches[1];
        $image = get_avatar( $post->post_author );

    return $image;
  • Hi thanks for you answer, I shall try you suggestion. FYI this themes has the capability to show featured images, else content pictures (from url or internal) else show the post-default.jpg if none of the picture is exists. I would like to keep this method but in last efforts instead showing the post-default.jpg I would like to show my author's avatar. Im thankfull for your suggestion and will try to apply it soon. I will return with my results. Jun 24, 2013 at 6:56
  • Hi FY, i did try your suggestion but the author images is missing. but I can see that author information is there when I hover the mouse on the missing picture/links. I would love to keep the methode showing the picture for this themes whcih is try to show featured images if any else images on posts if any and then the author images nsterad default jpeg. Jun 24, 2013 at 7:03
  • snag.gy/3Wzdz.jpg Jun 24, 2013 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.