忘備録。
アイキャッチ画像等が指定されない投稿でも、サムネイルとして画像を使いたい場合等に、投稿内にでてくる一番最初の画像で代替してしまおうという時に使うためのもの。
// 投稿内に出てくる一番最初の画像を取得する
function catch_post_image() {
global $post;
$first_img = '';
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
if (isset($matches[1])) {
$first_img = $matches[1][0];
}
if(empty($first_img)){
$first_img = '';
}
return $first_img;
}