3

On my website i would like to display the social locker wordpress plugin around a custom field.

<?php echo do_shortcode('[sociallocker]'.$to_lock.'[/sociallocker]');?>

Here is my custom field

<?php the_field('link'); ?>

Social locker requires a open and close shortcode:

[sociallocker id="16619"]
[/sociallocker]

The following does not work correctly:

<?php echo do_shortcode('[sociallocker id="16619"]'); ?>
<?php the_field('link'); ?>
<?php echo do_shortcode('[/sociallocker]'); ?>
1
  • 1
    Could you write then what does this code display on your HTML page? And have you tried to use <?= get_field ('link'); ?> instead of <?php the_field('link'); ?> Commented Nov 12, 2016 at 23:17

1 Answer 1

1

The function do_shortcode accept a single shortcode, you can't pass parts of the shortcode (open tag, content, closing tag) separately.

In case there is opening and closing shortcode, you should call it like following.

<?php echo do_shortcode( '[s_tag]' . $content . '[/s_tag]' ); ?>

So, you've to update your following lines to

<?php echo do_shortcode('[sociallocker id="16619"]'); ?>
<?php the_field('link'); ?>
<?php echo do_shortcode('[/sociallocker]'); ?>

With a single do_shortcode call.

<?php echo do_shortcode('[sociallocker id="16619"]' . get_field('link') . '[/sociallocker]'); ?>

Reference: https://developer.wordpress.org/reference/functions/do_shortcode/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.