• 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/

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