Title: Wrapping do_shortcode around additional php code
Last modified: August 21, 2016

---

# Wrapping do_shortcode around additional php code

 *  Resolved [matreece](https://wordpress.org/support/users/matreece/)
 * (@matreece)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/wrapping-do_shortcode-around-additional-php-code/)
 * Hi, I have some shortcode I’m trying to wrap around some additional php code.
   Basically I’ve downloaded a plugin that hides/reveals content which I wish to
   wrap around my comments box.
 * The two codes I have is –
 * <?php echo do_shortcode(‘[show-hide]’.$text_to_be_wrapped_in_shortcode.'[/show-
   hide]’); ?>
 * I want to replace the ‘$text_to_be_wrapped_in_shortcode’ with the below:
 * <?php if ( comments_open() || ‘0’ != get_comments_number() )
    comments_template();?
   >
 * Any ideas and help appreciated.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/wrapping-do_shortcode-around-additional-php-code/#post-3665411)
 * untested:
 *     ```
       <?php if ( comments_open() || '0' != get_comments_number() ) :
       ob_start();
       $comments_template();
       $comments_output = ob_get_contents();
       ob_end_clean();
       echo do_shortcode('[show-hide]'.$comments_output.'[/show-hide]');
       endif; ?>
       ```
   
 * [http://www.php.net/manual/en/function.ob-get-contents.php](http://www.php.net/manual/en/function.ob-get-contents.php)
 *  Thread Starter [matreece](https://wordpress.org/support/users/matreece/)
 * (@matreece)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/wrapping-do_shortcode-around-additional-php-code/#post-3665416)
 * Thanks for the code, however I’m getting an error saying:
 * Fatal error: Function name must be a string in /homepages/11/d388105143/htdocs…
 * Any ideas on how to fix this?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/wrapping-do_shortcode-around-additional-php-code/#post-3665514)
 * my mistake, an erraneous `$` before `comments_template()`;
 * corrected:
 *     ```
       <?php if ( comments_open() || '0' != get_comments_number() ) :
       ob_start();
       comments_template();
       $comments_output = ob_get_contents();
       ob_end_clean();
       echo do_shortcode('[show-hide]'.$comments_output.'[/show-hide]');
       endif; ?>
       ```
   
 *  Thread Starter [matreece](https://wordpress.org/support/users/matreece/)
 * (@matreece)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/wrapping-do_shortcode-around-additional-php-code/#post-3665588)
 * Fantastic – works perfectly…Many thanks!

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

The topic ‘Wrapping do_shortcode around additional php code’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [matreece](https://wordpress.org/support/users/matreece/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/wrapping-do_shortcode-around-additional-php-code/#post-3665588)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
