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"]

The following does not work correctly:

<?php echo do_shortcode('[sociallocker id="16619"]'); ?>
<?php the_field('link'); ?>
<?php echo do_shortcode('[/sociallocker]'); ?>
  • 2
    Use get_field with your first example. – Milo Nov 12 '16 at 23:56

Concatenate the shortcode with the field value just before you evaluate it with do_shortcode.

the_field('link') will automatically output the value while get_field('link') will return the value.

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

The problem you had before is that your evaluating the first 1/3 which doesn't include the data. Then you print the data. And again evaluate a close tag without data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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