Title: how to create shortcode for php function?
Last modified: August 31, 2016

---

# how to create shortcode for php function?

 *  Resolved [andrewf12](https://wordpress.org/support/users/andrewf12/)
 * (@andrewf12)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/how-to-create-shortcode-for-php-function/)
 * Hi,
 * Does anyone know if it’s possible to create a shortcode for the following function:`
   <?php comments_template(); ?>` ?
 * I would add this code to a shortcode plugin or something if that’s possible.
 * Thanks everyone for your help!

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/how-to-create-shortcode-for-php-function/#post-6905310)
 * Sorry, no. We define shortcodes with `add_shortcode()`, passing as an argument
   a function name to execute when the shortcode is encountered. But it cannot be
   any function, it must be a function that returns a single string to be output
   in place of the shortcode.
 * `comments_template()` does not return a single string, it includes another file
   in the current template. It would be conceivable to rewrite template output as
   a shortcode handler function, if you had a specific template file. But to handle
   any particular theme’s comment template you would not know what to rewrite.
 * Just an idea, completely untested: It may be possible to capture template file
   output using PHP’s output buffer, then assign the buffer contents to a variable.
   Your shortcode handler function would then return that variable. Not as simple
   as just calling `comment_template()`, but making something that works _might_
   be possible.

Viewing 1 replies (of 1 total)

The topic ‘how to create shortcode for php function?’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/how-to-create-shortcode-for-php-function/#post-6905310)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
