Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
427 B
3
Indexable
Never
category.php

<div class="margin-top-10 margin-bottom-10">
    <?php
    $img = catch_that_image(get_the_ID());
    if ($img) echo "<img src='$img'>";
    ?>
</div>

functions.php

function catch_that_image($post_id) {
    $post = get_post($post_id);
    preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $first_img = isset($matches[1][0]) ? $matches[1][0] : '';
    return $first_img;
}