Title: Function as snippet?
Last modified: December 15, 2016

---

# Function as snippet?

 *  Resolved [jwest100](https://wordpress.org/support/users/jwest100/)
 * (@jwest100)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/function-as-snippet/)
 * I have this shortcode in my functions.php file
 *     ```
       add_shortcode( 'buy_status', 'wpse249289_buy_status' );
       function wpse249289_buy_status( $atts ) {
           $output = '';
           if ( ! get_post_meta( get_the_ID(), 'buy_status', true ) ) {
               // Post meta value for key buy_status is false
               $output .= '<h5 style="text-align: center;display: block;">';
               $output .= 'Sorry, this piece is sold.';
               $output .= '</h5>';
           } else {
               // Post meta value for key buy_status is not false
               $output .= '<h5 style="text-align: center;display: none;"></h5>'; // Not sure why you'd want to output anything
           }
   
           return $output;
       }
       ```
   
 * I would like to put it in Post Snippets and call it from there. I’ve tinkered
   with doing that but can’t get it to work.
 * How would I put the code in Post Snippets? I assume the shortcode and php checkboxes
   would be checked?
 * Thanks!

The topic ‘Function as snippet?’ is closed to new replies.

 * ![](https://ps.w.org/post-snippets/assets/icon-128x128.gif?rev=2545587)
 * [Post Snippets - Custom WordPress Code Snippets Customizer](https://wordpress.org/plugins/post-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/post-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-snippets/reviews/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [Short Code](https://wordpress.org/support/topic-tag/short-code/)

 * 0 replies
 * 1 participant
 * Last reply from: [jwest100](https://wordpress.org/support/users/jwest100/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/function-as-snippet/)
 * Status: resolved