WordPress.org

Ready to get started?Download WordPress

Forums

cath_image function causing blank pages (2 posts)

  1. mediabros
    Member
    Posted 4 years ago #

    For some reason, the function below in my functions.php in theme folder seems to cause blank pages on saving anything in the admin section. Anyone got a idea what is causing this problem?

    <?php
    function catch_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)){
    	$first_img = "/images/default.jpg";
    	}
    	return $first_img;
    	}
    ?>
  2. mediabros
    Member
    Posted 4 years ago #

    i just placed a else on the bottom and now it seems to work, but it couldn't be that :o

    dunno, i am happy

    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)){
    	$first_img = "/images/default.jpg";
    	} else {
    	return $first_img;
    	}
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic