Using PHP WordPress variable do_shortcode for dynamic content

Rate this post

I’m building a WordPress site and my aim to have users be able to place custom shortcodes in the backend of WordPress on blog posts and have that content display on the site.

I’m using a simple text field Advanced Custom Field to do this (below.) but am struggling to integrate this with the do_shortcode variable.

Any help would be greatly appreciated, thanks.


Get Advanced Custom Field input to display as plaintext

<?php if( get_field('brand_video') ):?>
    <?php the_field('brand_video');?>
<?php endif;?>

Get WordPress to output video

<?php echo do_shortcode("
"); ?>

My attempt of combining the two

<?php if( get_field('brand_video') ):?>
    <?php echo do_shortcode(the_field('brand_video'));?>
<?php endif;?>



In do_shortcode replace the_field with get_field.

the_field is return a value. get_field is print a value.

<?php if( get_field('brand_video') ):?>
    <?php echo do_shortcode(get_field('brand_video'));?>
<?php endif;?>

Leave a Reply

Your email address will not be published.

Back to top button