記事の最初の画像を表示
- 2017.07.12
- CMS Wordpress
- function.php, ユーザー定義関数
// 記事の最初の画像を表示
function get_first_image_url($post){
// global $post;
if ( preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches) ) {
$first_img = $matches[1][0];
} else {
$first_img = get_template_directory_uri() . '/images/contents/no-image.jpg';
}
return $first_img;
}
-
前の記事
wordpressに“いいね”カウントを追加する(WP ULikeプラグイン) 2017.06.30
-
次の記事
使用しない管理メニューを非表示にする 2017.07.12