Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks in advance.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.