Title: add function to child theme function.php
Last modified: August 21, 2016

---

# add function to child theme function.php

 *  [adrian1986.li](https://wordpress.org/support/users/adrian1986li/)
 * (@adrian1986li)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/add-function-to-child-theme-functionphp/)
 * Hi I am using a child theme, I am a total beginner, I am not very good at understanding
   the code and would like to keep things clean and tidy.
 * so i did some copy & paste as told and got it work finally:
 *     ```
       function catch_that_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 = "/images/default.jpg";
         }
         return $first_img;
       }
       ```
   
 * Yet I would like to ask if there are any ways I can add the function catch_that_image()
   code in a child theme function.php, instead of putting it directly into the original
   parent theme?
 * i tried to do paste it inside a function.php in child theme any it only get errors.
   anyone would help me with some example?
    thx~
 * [http://wordpress.org/extend/plugins/get-the-image/](http://wordpress.org/extend/plugins/get-the-image/)

The topic ‘add function to child theme function.php’ is closed to new replies.

 * ![](https://ps.w.org/get-the-image/assets/icon-256x256.png?rev=1735614)
 * [Get the Image](https://wordpress.org/plugins/get-the-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/get-the-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/get-the-image/)
 * [Active Topics](https://wordpress.org/support/plugin/get-the-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/get-the-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/get-the-image/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [adrian1986.li](https://wordpress.org/support/users/adrian1986li/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/add-function-to-child-theme-functionphp/)
 * Status: not resolved