Title: Added function to functions.php, called function in snippet, not working
Last modified: September 16, 2022

---

# Added function to functions.php, called function in snippet, not working

 *  Resolved [amikor](https://wordpress.org/support/users/amikor/)
 * (@amikor)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/added-function-to-functions-php-called-function-in-snippet-not-working/)
 * Hi,
 * I added this code to my functions.php:
 *     ```
       function show_dimensions() {
          global $product;
          $dimensions = $product->get_dimensions();
          if ( ! empty( $dimensions ) ) {
             echo '<div class="dimensions"><b>Height:</b> ' . $product->get_height() . get_option( 'woocommerce_dimension_unit' );
             echo '<br><b>Width:</b> ' . $product->get_width() . get_option( 'woocommerce_dimension_unit' );
             echo '<br><b>Length:</b> ' . $product->get_length() . get_option( 'woocommerce_dimension_unit' );
             echo '</div>';        
          }
       }
       ```
   
 * Then I added this snippet to the editor of the plugin:
    `show_dimensions(); ?
   >`
 * And nothing is displaying in the front-end where I’m using the shortcode.
    I 
   tried this with other plugins and they worked on front-end, but gave me a 500
   error in the WP editor. Now I can’t even get to the 500 error 😀

Viewing 1 replies (of 1 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/added-function-to-functions-php-called-function-in-snippet-not-working/#post-16022093)
 * Hi [@amikor](https://wordpress.org/support/users/amikor/),
 * You’re likely not getting a 500 error because WPCode is attempting to catch the
   error. Regarding why the shortcode is not working, my first guess would be that
   the global `$product` you are trying to use there is not populated so you’re 
   trying to access an object that doesn’t exist. Are you using this on the single
   page of a product?
 * You can probably add a check there to make sure the `$product` is a WooCommerce
   product to clear things up, something like:
 *     ```
       	if ( ! $product instanceof WC_Product ) {
       		return;
       	}
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Added function to functions.php, called function in snippet, not working’
is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/added-function-to-functions-php-called-function-in-snippet-not-working/#post-16022093)
 * Status: resolved