Title: Including Shortcode Within a Figure
Last modified: August 24, 2016

---

# Including Shortcode Within a Figure

 *  Resolved [nateonawalk](https://wordpress.org/support/users/natesirrah/)
 * (@natesirrah)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/)
 * Hey Micah,
 * On my [new ‘lil Pokemon site](http://eeveelutions.com), I’m trying to add a call
   to Widgets on Pages Shortcode within the figure generated by mPress. I’d like
   to be able to put responsive objects on both the **left **and **right **of the
   central random image found within the iFrame (you can see an example of this 
   when you click the “eevolve” button on the homepage). Because the `figure` is
   displayed as a block, I’d like to float these widget sidebars within the same
   div (and as a result, the same figure).
 * I’ve made two widgets with WOP and put some filler text. I titled them “Sidebar1_Left”
   and “Sidebar2_Right.” The correct shortcodes for these two widgets are:
 * [widgets_on_pages id=”Sidebar1_Left”]
    & [widgets_on_pages id=”Sidebar2_Right”],
 * respectively.
 * I tried to simply insert these into the plugin between the <figure> tags using
   the _php echo do\_shortcode_ function:
 *     ```
       if ( $display_caption ) {
       					$image_html = "<figure>
       						<?php echo do_shortcode('[widgets_on_pages id="Sidebar1_Left"]'); ?>
       					{$image_html}<figcaption>{$image->post_excerpt}</figcaption>
       						<?php echo do_shortcode('[widgets_on_pages id="Sidebar2_Right"]'); ?>
       					</figure>";
       				}
       ```
   
 * …but that broke the site with a T-String error.
 * And so I’m stumped! Could you advise either the 1) correct place for me to put
   this code or 2) an alternate approach to solving the puzzle?
 * Thanks so much!
    -NS
 * [https://wordpress.org/plugins/mpress-image-refresh/](https://wordpress.org/plugins/mpress-image-refresh/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Micah Wood](https://wordpress.org/support/users/woodent/)
 * (@woodent)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020566)
 * There is a filter that will allow you to edit the output without editing the 
   actual plugin. Editing the plugin files is discouraged as you would lose your
   changes when the plugin is updated in the future.
 * You can create a file in your `wp-content/plugins/` directory and place this 
   code in it to edit the output to fit your needs:
 *     ```
       <?php
   
       /*
        * Plugin Name: mPress Image Refresh - Custom Output
        */
   
       add_filter( 'mpress_image_refresh-image_html', function ( $image_html, $image, $atts ) {
       	$image_html = '<figure>';
       	$image_html .= do_shortcode( '[widgets_on_pages id="Sidebar1_Left"]' );
       	$image_html .= "<figcaption>{$image->post_excerpt}</figcaption>";
       	$image_html .= do_shortcode( '[widgets_on_pages id="Sidebar2_Right"]' );
       	$image_html .= '</figure>';
   
       	return $image_html;
       }, 10, 3 );
       ```
   
 * I didn’t test it, but it should be correct. If it doesn’t work for you, just 
   let me know.
 *  Thread Starter [nateonawalk](https://wordpress.org/support/users/natesirrah/)
 * (@natesirrah)
 * [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020695)
 * Dear Micah, thanks for this! I haven’t yet been able to get the code working…
   I inserted it character-for-character into a PHP file, which I called “mpress-
   filter.php,” and put that file in the `wp-content/plugins` directory of my site.
 * To get it to work,
    -  Do I need to name it something different?
       Do I need to actually place the
      file in the mpress-image-refresh folder? Is it that the widgets are just getting
      sized out by the other figure element in the iFrames? I’m not able to see 
      the widgets_on_pages by digging around in the DOM code.
 *  Thanks again for your help!
    Best,
 * -NS
 *  [Micah Wood](https://wordpress.org/support/users/woodent/)
 * (@woodent)
 * [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020697)
 * Sorry, I didn’t mention activating the plugin, but that is a required step after
   placing the file in the `wp-content/plugins/` directory. The file name you used
   is just fine. If you place the file in the mpress-image-refresh folder, it won’t
   work.
 * This function will actually process the `[widgets_on_pages]` shortcode immediately,
   so you won’t see the shortcode output in the DOM unless the widget is disabled.
   You would always just change the `return $image_html;` line to something like`
   return 'Hello World!';` just to see if it is working properly.
 * If you still can’t get it to work, then feel free to shoot me an email and we
   can figure out a way that I can take a closer look.
 *  Thread Starter [nateonawalk](https://wordpress.org/support/users/natesirrah/)
 * (@natesirrah)
 * [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020698)
 * Hey Micah,
 * So I went ahead and activated the plugin, I had indeed missed that step — when
   I tested my page, blog posts showed a blank page with this error:
    -  Warning: Cannot modify header information – headers already sent by (output
      started at `/wp-content/plugins/mpress-filter.php:18`) in `wp-includes/pluggable.
      php` on line 1196
 * which seems to imply an issue in the Loop?
 * Thanks again for all the help!
    -NS
 *  [Micah Wood](https://wordpress.org/support/users/woodent/)
 * (@woodent)
 * [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020700)
 * [@natesirrah](https://wordpress.org/support/users/natesirrah/),
 * It is likely that there may be an extra space before the opening `<?php` tag 
   from when you copied the code into the file. Removing any spaces should solve
   the issue.
 *  Thread Starter [nateonawalk](https://wordpress.org/support/users/natesirrah/)
 * (@natesirrah)
 * [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020702)
 * Dear Micah,
 * I believe the problem ended up being either two extra lines at the end of the
   file, or a space before a */…whichever it was, the plugin no longer breaks posts,
   which is great!
 * Instead, there is another issue — either a) the image that the original plugin
   was pulling no longer appears [and the two text widgets I’m pulling with the 
   new filter do] or b) an image appears, but it is no longer random.
 * For the sake of clarity,[ here is the site](http://eeveelutions.com/). When a
   visitor clicks the main button, a lightbox activates that renders 1/8 posts randomly.
   6/8 of those posts now **only **render the `widgets_on_pages` text widgets and
   the `figcaption`; 2/8 of the pages render an image from my bank of random images,
   but they are no longer random (Jolteon and Espeon). Every time a user gets a 
   Jolteon or Espeon page, it is the same artwork.
 * At its normal functionality (with the new filter plugin disabled), on click the
   site renders a lightbox with 1/8 of the posts, and that post has mPress shortcode
   that pulls from a span of relevant random images.
 * Thanks again Micah! Do you have a donate button on your site?
    Best,
 * -Nate
 *  [Micah Wood](https://wordpress.org/support/users/woodent/)
 * (@woodent)
 * [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020703)
 * It is sounding like there may be some issues specific to the context you are 
   working with, but I’m not sure of the details. I’ll shoot you an email and follow
   up, since it may require getting admin access to the site to see what exactly
   is going on.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Including Shortcode Within a Figure’ is closed to new replies.

 * ![](https://ps.w.org/mpress-image-refresh/assets/icon-256x256.png?rev=3200416)
 * [Image Refresh](https://wordpress.org/plugins/mpress-image-refresh/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mpress-image-refresh/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mpress-image-refresh/)
 * [Active Topics](https://wordpress.org/support/plugin/mpress-image-refresh/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mpress-image-refresh/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mpress-image-refresh/reviews/)

## Tags

 * [float](https://wordpress.org/support/topic-tag/float/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * 7 replies
 * 2 participants
 * Last reply from: [Micah Wood](https://wordpress.org/support/users/woodent/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/including-shortcode-within-a-figure/#post-6020703)
 * Status: resolved