0

I am using wordpress. I am using the plugin social locker.

I have figured out how to display the shortcode via PHP:

<?php echo do_shortcode('[sociallocker id="3071"] My content Here [/sociallocker]'); ?>

However I want to display this button that will allow for a print popup in between there.

This code is:

<?php if ( function_exists( 'pdf_print_popup' ) ) pdf_print_popup(); ?>

So my question is can I do this:

<?php echo do_shortcode('[sociallocker id="3071"] <?php if ( function_exists( 'pdf_print_popup' ) ) pdf_print_popup(); ?> [/sociallocker]'); ?>

If not what do I need to do? My goal is to make it so the social locker dissapears once the user shares and they see the print button.

Thanks Guys :)

  • My guess is that you need to write your own shortcode but the details depend on the plugin. – s_ha_dum Mar 16 '14 at 0:40
2

You're close but not quite.

do_shortcode expects a string so give it one!


If function() returns a string you can

echo do_shortcode( '[shortcode]' . function() . '[/shortcode]' );

If function() directly outputs, you can capture its output using output buffering

//start the buffer
ob_start();

function();  //i.e pdf_print_popup();

//store out output buffer
$string = ob_get_contents();

//clear the buffer and close it
ob_end_clean();

and then use the string we stored

echo do_shortcode( '[shortcode]' . $string . '[/shortcode]' );

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.