[wp-hackers] Problems with shortcode function in plugin

Mike Schinkel mikeschinkel at gmail.com
Mon Dec 29 19:53:53 GMT 2008


Ade Walker wrote:
> So, I added the add_shortcode hook to my plugin file, and call the main
plugin function within this hook.

Would love to see a sample of the code once you get it working.


Aaron D. Campbell wrote:

> You can do something like this:
>
> function whatever($echo=false) {
>   $output = '';
>   foreach(){
>       $output .= "something";
>   }
>   if ($echo)
>       echo $output;
>   return $output;
> }
>

This is more of a PHP question, but given what I assume are negative
performance implications of string concatenation in a loop for a large
number of items, I've always used the following since I've come to PHP:

function whatever($echo=false) {
    $output = array();
    foreach(){
        $output[] = "something";
    }
    $output = implode('',$output);
    if ($echo)
        echo $output;
    return $output;
}

Anyone else has thoughts on this?

-Mike Schinkel
http://mikeschinkel.com


More information about the wp-hackers mailing list