• I’m a bit of a newbie at PHP… Let’s say I write a function that emits a bunch of html:

    function foo() {
       echo "<p>";
       foreach( $somelist as $someitem ) {
          echo $someitem->somefield;
       }
       echo "</p>";
    }

    If I want to make this into shortcode, then it needs to ‘return’ the html rather than echo it. For example:

    function foo() {
       result=''
       result=result."<p>";
       foreach ( $somelist as $someitem ) {
          result=result.$someitem.somefield;
       }
       result=result."</p>";
       return result;
    }

    This looks somewhat inelegant and actually downright messy as the shortcode function gets more complex and I need to output more html. Is there any kind of a PHP shortcut that I’m missing or a better way to output wordpress shortcode than to use repeated string concatenations?

    thanks,
    scott

The topic ‘Returning shortcode html’ is closed to new replies.