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('[audio src="enclosure"]');?>

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

<?php echo get_post_meta($post->ID, '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('[audio src="'. get_post_meta($post->ID, 'enclosure', true)  .'"]');?>


$enclosure = get_post_meta($post->ID, 'enclosure', true);
echo do_shortcode('[audio src="'. $enclosure . '"]';

Your Answer

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

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