0

How do I fit a function inside an opening and closing shortcode.

I have this function that displays the post's pdf attachment url

$file= get_post_meta( $post->ID, 'teacher-resume-upload' ); 
if ( $file) { foreach ( $file as $attachment_id ) { $full_size = wp_get_attachment_url( $attachment_id ); 
printf( '%s', $full_size); } }

How would I fit the above code into this...

echo do_shortcode( '[pdf]' . $text_to_be_wrapped_in_shortcode . '[/pdf]' );
1

This should work assuming your trying to pass the URL to the PDF short code

$file= get_post_meta( $post->ID, 'teacher-resume-upload' ); 
if ( $file) { 
   foreach ( $file as $attachment_id ) { 
       $full_size = wp_get_attachment_url( $attachment_id ); 
       echo do_shortcode( '[pdf]' . $full_size . '[/pdf]' );
    }  
}
0

Worked it out...

<?php $file= get_post_meta( $post->ID, 'teacher-resume-upload' ); $full_size = wp_get_attachment_url( $attachment_id );?>
<?php echo do_shortcode( '[pdf]' . $full_size . '[/pdf]' ); ?>

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.