Maxim Zubarev
Maxim Zubarev

Reputation: 2473

Output edited shortcode content, not return it

is it possible somehow to execute / print content in a WordPress shortcode filter, not return it? I mean, shortcode functions in general return output, but do not print. If I tell my shortcode function to print, it outputs the worked trough shortcode content right in the beginning of all content and I don not have any possibility to work with it any more.

I really hope, someone can help me, if someony has understood what I mean ;)

Best regards, .wired

Upvotes: 1

Views: 501

Answers (1)

EarnestoDev
EarnestoDev

Reputation: 507

Easy! Use output buffering.

ob_start(); // content is no longer output but is captured internally
echo 'buffered output'; // business as usual
$output = ob_get_contents(); // pass captured content to variable and
// terminate output buffering (echo beyond this point prints again)
return $output; // or play with it some more

PHP rules!

Upvotes: 1

Related Questions