Title: Help needed extending custom function
Last modified: August 18, 2016

---

# Help needed extending custom function

 *  Resolved [tom_de_schlong](https://wordpress.org/support/users/tom_de_schlong/)
 * (@tom_de_schlong)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-needed-extending-custom-function/)
 * Hi all I am using the following custom function to display a thumbnail automatically
   taken from the first image in the post and it works great.
 *     ```
       <?php // This Function Powers the thumbnail image that is used in my portfolio
       function return_ThumbNail($Thumb) {
       if (preg_match('/<img[^>]*>/',$Thumb,$Treffer)) {
       $Thumb = preg_replace('/(<img ).*(src=\'[^\']*\').*( \/>)/','$1$2$3',$Treffer[0]);
       $Thumb = preg_replace('/(.[^.]* \/>)/','.thumbnail$1',$Thumb);
       } else {
       $Thumb = false;
       }
       return $Thumb;
       }
       ?>
       ```
   
 * I would like to extend this function to also pass the thumbnail the relevant “
   alt” text. I know this is probably simple but my php regular expression skills
   are not very good.
 * Tom

Viewing 1 replies (of 1 total)

 *  Thread Starter [tom_de_schlong](https://wordpress.org/support/users/tom_de_schlong/)
 * (@tom_de_schlong)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-needed-extending-custom-function/#post-562232)
 * Solved it myself
 *     ```
       <?php // This Function Powers the thumbnail image that is used in my portfolio
       function return_ThumbNail($Thumb) {
       if (preg_match('/<img[^>]*>/',$Thumb,$Treffer)) {
       $Thumb = preg_replace('/(<img ).(alt=\'\').*(src=\'[^\']*\').*( \/>)/','$1$2$3',$Treffer[0]);
       $Thumb = preg_replace('/(.[^.]* \/>)/','.thumbnail$1',$Thumb);
       } else {
       $Thumb = false;
       }
       return $Thumb;
       }
       ?>
       ```
   
 * Tom

Viewing 1 replies (of 1 total)

The topic ‘Help needed extending custom function’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 1 reply
 * 1 participant
 * Last reply from: [tom_de_schlong](https://wordpress.org/support/users/tom_de_schlong/)
 * Last activity: [18 years, 11 months ago](https://wordpress.org/support/topic/help-needed-extending-custom-function/#post-562232)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
