Title: [Plugin: Code Snippets] Code formatting
Last modified: August 20, 2016

---

# [Plugin: Code Snippets] Code formatting

 *  Resolved [sorto](https://wordpress.org/support/users/sorto/)
 * (@sorto)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/)
 * I have a code snippet I like to use to place a default image for a category when
   there is not one already on the post. I am having trouble getting it to work 
   in this plugin. Thoughts?
 *     ```
       // category-specific post thumbnails
       function category_specific_post_thumbnails() {
       	if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) {
       		the_post_thumbnail('thumbnail');
       	} else {
       		$category = get_the_category();
       		//echo '<img src="'. get_bloginfo('template_directory') .'images'. $category[0]->cat_name .'.png">'; 
   
       	}
       }
       ```
   
 * [http://wordpress.org/extend/plugins/code-snippets/](http://wordpress.org/extend/plugins/code-snippets/)

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

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/#post-2974033)
 * Hello,
    It looks like you’re missing some code. Try re-copying it from where 
   you found it. You’re looking for a line something like `add_action( <em>hook_name
   </em>, 'category_specific_post_thumbnails' );` or `add_filter( <em>hook_name</
   em>, 'category_specific_post_thumbnails' );` where _hook\_name_ could be almost
   anything.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/#post-2974047)
 * Did you have any luck getting your snippet to work?
 *  Thread Starter [sorto](https://wordpress.org/support/users/sorto/)
 * (@sorto)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/#post-2974062)
 * I did not. I added the add_action with tag of transition_post_status and now 
   I see and error message:
 * Warning: Cannot modify header information – headers already sent by (output started
   at /wp-content/plugins/code-snippets/code-snippets.php(398) : eval()’d code:8)
   in /wp-includes/pluggable.php on line 881
 * The add_action code:
 * add_action( ‘transition_post_status’, ‘category_specific_post_thumbnails’ );
 * I received this error on all of the post modification hooks(post_publish, post_save,
   etc). It is probably not the correct hook for the code.
 * I have a series of posts that get published via RSS feeds and they come in without
   featured images, so no thumbnail on the main pages but they all go to the same
   category. I had hoped to set the featured image for all new published posts in
   this category to a single image for that category. I can accomplish this by changing
   the functions.php, but prefer your tool for theme upgrades/changes, visibility,
   etc.
 * I am very skilled with PHP, though, so this may be a bit out of reach.
 * Also, a feature request – is it possible to create a central repository for all
   code snippets? It would be pretty great to create a library of snippets that 
   can be used on multiple sites.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/#post-2974063)
 * Such libraries already exist:
    - [WP-Snippets](http://wp-snippets.com)
    - [WP Snipp](http://wpsnipp.com)
    - [Cats Who Code](http://www.catswhocode.com/blog/snippets)
    - [WP Function Me](http://www.wpfunction.me/)
 * Also see:
    - [This post](http://managewp.com/using-functions-php) and [this post](http://managewp.com/wordpress-code-snippets-that-replace-plugin-functionality)
      on the [ManageWP Blog](http://managewp.com/blog)
    - [WPMU.org Blog](http://wpmu.org)
 * There are plenty more out there.
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/#post-2974066)
 * Try hooking it to these filters:
 *     ```
       add_filter('the_excerpt_rss', 'category_specific_post_thumbnails');
       add_filter('the_content_feed', 'category_specific_post_thumbnails');
       ```
   
 * Let me know if it works.

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

The topic ‘[Plugin: Code Snippets] Code formatting’ 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/)

 * 5 replies
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-code-snippets-code-formatting/#post-2974066)
 * Status: resolved