Call a custom field in an audio shortcode?

I’m attempting to call a custom field in an audio shortcode. The field I’m calling, enclosure, defines MP3 files that are associated with my respective posts. I’m using the PHP template editor in WordPress. Here’s what I have.

<?php echo do_shortcode('https://wordpress.stackexchange.com/questions/212077/enclosure');?>

I would like to insert the following code in place of the word “enclosure.”

<?php echo get_post_meta($post->ID, "https://wordpress.stackexchange.com/questions/212077/enclosure", true); ?>

I either get the code displayed as text or nothing at all when I paste these snippets together. What am I missing?

1 Answer
1

Try using PHP’s string concatenation:

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

or:

<?php
$enclosure = get_post_meta($post->ID, "https://wordpress.stackexchange.com/questions/212077/enclosure", true);
echo do_shortcode(''. $enclosure . '';
?>

Leave a Comment