Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Keep image captions attached to image when spliting post content WordPress


I have a WP site running with the following code used to split and display the post images and content in two seperate columns -

<div class="wrapper portfolio-page-single">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<div class="post">
the_content('Read the full post',true);
$postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
echo $postOutput;
<?php //the_content() ; ?>
preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
echo $beforeEachImage . preg_replace( '/(width|height)="\d*"\s/', "", $matches[1][$i]) . $afterEachImage;}
<?php endwhile; ?>
<?php endif; ?>
<div class="both"></div>
<div class="both"></div>

It works well, with the text displayed in the 'article' area and the images displayed in the 'aside' area. The problem is now that I am adding PayPal buttons to the images, the captions are also being stripped off the images and incorrectly displayed in the 'article' area.

How can I alter this code to keep the captions attached to the images?

I cannot provide a url to the page as it is on a private client sever.

Thanks in advance.

Answers (0)

No answers yet.