Title: Returning shortcode html
Last modified: August 19, 2016

---

# Returning shortcode html

 *  [smbaker](https://wordpress.org/support/users/smbaker/)
 * (@smbaker)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/returning-shortcode-html/)
 * 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.

 * 0 replies
 * 1 participant
 * Last reply from: [smbaker](https://wordpress.org/support/users/smbaker/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/returning-shortcode-html/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
