wordpress - PHP and Shortcode Combination -
on website display social locker wordpress plugin around custom field.
<?php echo do_shortcode('[sociallocker]'.$to_lock.'[/sociallocker]');?>
here custom field
<?php the_field('link'); ?>
social locker requires open , close shortcode:
[sociallocker id="16619"] [/sociallocker]
the following not work correctly:
<?php echo do_shortcode('[sociallocker id="16619"]'); ?> <?php the_field('link'); ?> <?php echo do_shortcode('[/sociallocker]'); ?>
the function do_shortcode
accept single shortcode, can't pass parts of shortcode (open tag, content, closing tag) separately.
in case there opening , closing shortcode, should call following.
<?php echo do_shortcode( '[s_tag]' . $content . '[/s_tag]' ); ?>
so, you've update following lines
<?php echo do_shortcode('[sociallocker id="16619"]'); ?> <?php the_field('link'); ?> <?php echo do_shortcode('[/sociallocker]'); ?>
with single do_shortcode
call.
<?php echo do_shortcode('[sociallocker id="16619"]' . get_field('link') . '[/sociallocker]'); ?>
reference: https://developer.wordpress.org/reference/functions/do_shortcode/
Comments
Post a Comment