Featured Image Fallback and remove first image in post. (1 post)

  1. spitnale
    Posted 3 years ago #

    I am having issues with my code for featured posts. Here what it does:

    1. If has featured image > Show
    2. If doesnt > Show first image in post (also need to delete first image in post)
    3. If no image in post and no featured image > default.jpg

    What i need is to delete the first image in the post so it does not repeat (#2). I dont know where to start any help

    Here is the code:

    function get_fbimage() {
      if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) {
      $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '', '' );
      $fbimage = $src[0];
      } else {
        global $post, $posts;
        $fbimage = '';
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
        $post->post_content, $matches);
        $fbimage = $matches [1] [0];
      if(empty($fbimage)) {
        $fbimage = "http://www.example.com/defualt.jpg";
      return $fbimage;

Topic Closed

This topic has been closed to new replies.

About this Topic