Title: Error 500
Last modified: August 15, 2018

---

# Error 500

 *  Resolved [semperaye](https://wordpress.org/support/users/semperaye/)
 * (@semperaye)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/error-500-86/)
 * Hi. I keep getting either: “The snippet has been deactivated due to an error 
   on line 4: syntax error, unexpected ‘$html’ (T_VARIABLE)”, or an error 500 when
   I add the following snippet:
 *     ```
       add_shortcode('post_cats', 'sa_show_cats');
       function sa_show_cats() {
         $cats = wp_get_post_categories( get_the_ID(), ['fields'=>'all',]);
         $html = array();
         foreach ( $cats as $cat ) {
           $url = site_url("/category/{$cat->slug}/");
           $html[] = "<a class=\"sa-cat-links\" href=\"$url\">{$cat->name}</a>";
         }
         return implode( $html, ', ');
       }
       ```
   

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

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/error-500-86/#post-10598939)
 * Hi,
 * I can’t see any syntax issues in the snippet you posted. The only thing I can
   think of is perhaps there’s an issue with the use of the short array syntax on
   line 3?
 * Perhaps you could try switching out that line with this:
 * `$cats = wp_get_post_categories( get_the_ID(), array( 'fields' => 'all' ) );`
 *  Thread Starter [semperaye](https://wordpress.org/support/users/semperaye/)
 * (@semperaye)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/error-500-86/#post-10601583)
 * Thank your taking a look into this for me! Unfortunately your suggested change
   in code did not fix the error 500.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/error-500-86/#post-10609157)
 * Unfortunately, I can’t really say for sure what might be causing the issue without
   more information, but I’ve rewritten the snippet slightly – perhaps you could
   try this out and see whether it works?
 *     ```
       add_shortcode( 'post_cats', function () {
       	$cats = wp_get_post_categories( get_the_ID(), array( 'fields' => 'all' ) );
       	$html = array();
   
       	foreach ( $cats as $cat ) {
       		$html[] = sprintf(
       			'<a class="sa-cat-links" href="%s">%s</a>',
       			get_term_link( $cat, 'category' ),
       			$cat->name
       		);
       	 }
   
       	return implode( $html, ', ' );
       } );
       ```
   
 *  Thread Starter [semperaye](https://wordpress.org/support/users/semperaye/)
 * (@semperaye)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/error-500-86/#post-10610697)
 * Shea,
 * THANK YOU!! This works perfectly! I wonder what the issue was??!
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/error-500-86/#post-10620426)
 * it’s difficult to say, but I suspect it has to do with escaping double quotation
   marks on line 7. `sprintf()` is a great alternative for these situations.

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

The topic ‘Error 500’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

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

 * 5 replies
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/error-500-86/#post-10620426)
 * Status: resolved