Title: When i place custom code
Last modified: June 15, 2021

---

# When i place custom code

 *  Resolved [garybultitude](https://wordpress.org/support/users/garybultitude/)
 * (@garybultitude)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/when-i-place-custom-code/)
 * Hi, I can see from your plugin that if an image has not been uploaded to a post…
   the post can have an image, specific to the category it is in…
 * I have tried adding the to my functions.php but it gives me an error, even before
   I upload it… Am I placing it in the wrong place?
 * Kind regards
 * Gary
 *     ```
       function dfi_category ( $dfi_id, $post_id ) {
         // all which have 'animals' as a category
         if ( has_category( 'animals', $post_id ) ) {
   
           //sub category
           if ( has_category( 'cats', $post_id ) ) {
             return 7; // cats img
           } else if has_category( 'dogs', $post_id ) {
             return 8; // dogs img
           }
   
           return 6; // default animals picture
         }
         return $dfi_id; // the original featured image id
       }
       add_filter( 'dfi_thumbnail_id', 'dfi_category', 10, 2 );
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwhen-i-place-custom-code%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Jan-Willem](https://wordpress.org/support/users/janwoostendorp/)
 * (@janwoostendorp)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/when-i-place-custom-code/#post-14558946)
 * Hello Gary,
 * There is a typo in the example code on the plugin page.
    I’ll have to fix that.
 * For now this is the error:
    Wrong `} else if has_category( 'dogs', $post_id ){`
   Correct `} else if ( has_category( 'dogs', $post_id ) ) {`
 * Let me know how it goes.
 * Jan-Willem

Viewing 1 replies (of 1 total)

The topic ‘When i place custom code’ is closed to new replies.

 * ![](https://ps.w.org/default-featured-image/assets/icon-256x256.jpg?rev=1058491)
 * [Default Featured Image](https://wordpress.org/plugins/default-featured-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/default-featured-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/default-featured-image/)
 * [Active Topics](https://wordpress.org/support/plugin/default-featured-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/default-featured-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/default-featured-image/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Jan-Willem](https://wordpress.org/support/users/janwoostendorp/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/when-i-place-custom-code/#post-14558946)
 * Status: resolved