Home › Forums › CSS › Get the URL from the image I inserted in the HTML Editor. › Re: Get the URL from the image I inserted in the HTML Editor.
August 21, 2012 at 5:19 pm
#108296
chrisburton
Participant
Using a function, I believe I have solved the issue.
I placed this code in my functions.php file that allows me to grab the very first image in a post.
// CREATES A FUNCTION TO GRAB FIRST IMAGE OF A POST
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
From there I can echo the URL using the following
The end result would look like this
$meta = $custom_metabox->the_meta('description', TRUE);
if (!empty($meta)):
echo ''.$meta.'
'; ?>
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments );
if( $total_attachments ) : ?>