Skip to content

Instantly share code, notes, and snippets.

View rafiul's full-sized avatar
🏠
Working from home

B.M. Rafiul Alam rafiul

🏠
Working from home
View GitHub Profile
@rafiul
rafiul / Get WordPress first image of posts
Last active July 13, 2019 16:17
Get WordPress first image of posts if featured image not provided.
//=======Function of get first image of posts ========
function get_first_image_of_posts() {
global $post;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+?src=[\'"]([^\'"]+)[\'"].*?>/i', $post->post_content, $matches);
$first_img = $matches[1][0];