Title: Add default image for widget
Last modified: August 20, 2016

---

# Add default image for widget

 *  [koruitch](https://wordpress.org/support/users/koruitch/)
 * (@koruitch)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/add-default-image-for-widget/)
 * I have a problem to show image gd star rating widget. I use image from content
   with %image% and working properly but i want show a image if the post no content
   images. I use
 *     ```
       function get_first_image() {
           global $post, $posts;
           $first_img = '';
           ob_start();
           ob_end_clean();
           $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
           $first_img = $matches [1] [0];
   
           if(empty($first_img)){ //Defines a default image
               $first_img = "/noimage.jpg";
           }
           return $first_img;
       }
       ```
   
 * in my theme but I do not integrate into template t2, I also edit render.php in
   line:
 *     ```
       if ($widget["image_from"] == "content") {
                           $row->image = gdFunctionsGDSR::get_first_image($row->post_content);
                       } else if ($widget["image_from"] == "custom") {
                           $row->image = get_post_meta($row->post_id, $widget["image_custom"], true);
                       } else $row->image = "";
       ```
   
 * But without success.
    How I can display a default image if the post no content
   image?
 * [http://wordpress.org/extend/plugins/gd-star-rating/](http://wordpress.org/extend/plugins/gd-star-rating/)

The topic ‘Add default image for widget’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gd-star-rating_333071.svg)
 * [GD Star Rating](https://wordpress.org/plugins/gd-star-rating/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gd-star-rating/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gd-star-rating/)
 * [Active Topics](https://wordpress.org/support/plugin/gd-star-rating/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gd-star-rating/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gd-star-rating/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [koruitch](https://wordpress.org/support/users/koruitch/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/add-default-image-for-widget/)
 * Status: not resolved