0

A client of mine wishes to use the plugin Content Locker. The template in question doesn't have a content area the client can use and hence I need to use the do_shortcode function.

I know how to implement but not close?

<?php do_shortcode('[signinlocker id="506"]'); ?>
  <div class="column">
    <div class="columns resource_downloads">
    <?php if ( have_rows('_downloads_group') ) : ?>
    <?php while( have_rows('_downloads_group') ) : the_row(); ?>
      <div class="column v-align-top">
        <figure class="download__img outer-1by1">
          <img class="inner-1by1" src="<?php echo wp_get_attachment_image_src( get_sub_field('_file_image'), 'download' )[0]; ?>" alt="<?php the_field('_file_image_alt'); ?>" width="150" height="150">
        </figure>
        <div class="resource_downloads-info stack__sm">
          <h3><?php the_sub_field('_file_title'); ?></h3>
          <p><?php the_sub_field('_file_description'); ?></p>
        </div>
        <div class="btn-wrap">
         <a class="button primary" href="<?php the_sub_field('_file_download_button'); ?>" title="<?php the_sub_field('_file_download_button_title'); ?>"><?php the_sub_field('_file_download_button_label'); ?></a>
        </div>
      </div>
    <?php endwhile; ?>
    <?php endif; ?>
  </div>
</div>
<?php do_shortcode('[/signinlocker]'); ?> // This is not correct?

I have too much "content" to use the echo do_shortcode( '[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]' ); example in the WordPress documentation.

How can I "wrap" the necessary code with [signinlocker id="506"] shortcode.

3
  • I have too much "content", what do you mean by that? you need to loop that content and thats the problem? Commented Nov 16, 2021 at 11:19
  • There are multiple lines of looped php and html, hence I think too much for a variable. The content is slightly irrelevant. The issue is the shortcode needs to wrap around whatever it contains. Commented Nov 16, 2021 at 11:25
  • A variable is just a container, if the final content is 100% string, no object and arrays, there should be no problem doing that. If you have less then 2GB string you should not have problems Commented Nov 16, 2021 at 11:28

1 Answer 1

0

Using output buffering seems like the way to go in this case, ob_start() to start buffering, then ob_get_clean() to get and clean the buffering.

<?php ob_start(); ?>
  <div class="column">
    <div class="columns resource_downloads">
    <?php if ( have_rows('_downloads_group') ) : ?>
    <?php while( have_rows('_downloads_group') ) : the_row(); ?>
      <div class="column v-align-top">
        <figure class="download__img outer-1by1">
          <img class="inner-1by1" src="<?php echo wp_get_attachment_image_src( get_sub_field('_file_image'), 'download' )[0]; ?>" alt="<?php the_field('_file_image_alt'); ?>" width="150" height="150">
        </figure>
        <div class="resource_downloads-info stack__sm">
          <h3><?php the_sub_field('_file_title'); ?></h3>
          <p><?php the_sub_field('_file_description'); ?></p>
        </div>
        <div class="btn-wrap">
         <a class="button primary" href="<?php the_sub_field('_file_download_button'); ?>" title="<?php the_sub_field('_file_download_button_title'); ?>"><?php the_sub_field('_file_download_button_label'); ?></a>
        </div>
      </div>
    <?php endwhile; ?>
    <?php endif; ?>
  </div>
</div>
<?php
$output = ob_get_clean();
echo do_shortcode('[signinlocker id="506"]' . $output . '[/signinlocker]');
?>
1
  • This looks good, but it currently isn't working. I'm just having the client check their API and I'm double checking the settings. Thanks in advance Commented Nov 16, 2021 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.