Title: adding different header codes, based on WP categories
Last modified: January 17, 2018

---

# adding different header codes, based on WP categories

 *  [agrycult](https://wordpress.org/support/users/agrycult/)
 * (@agrycult)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/adding-different-header-codes-based-on-wp-categories/)
 * Hallo!
    I need to add a dozen of different javascript codes, based on the catogories/
   tags of the posts.
 * For example:
 * – posts tagged with “red” should be get the “red” version of the code (in the
   body)
    – posts tagged with “green” should be get the “green” version of the code(
   in the body)
 * Do you know how I could achieve that?
 * Thank you
 * Michele

Viewing 1 replies (of 1 total)

 *  Plugin Author [Aleksandar Urošević](https://wordpress.org/support/users/urkekg/)
 * (@urkekg)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/adding-different-header-codes-based-on-wp-categories/#post-9875083)
 * Hi [@agrycult](https://wordpress.org/support/users/agrycult/),
 * I’m not clearly sure what you trying to achieve, but you could look for post 
   tag links, and run JS code which you need for that particular tag.
 * For example, here is an code example for default WP theme Twenty Fifteen which
   will run on single posts only if post have tags green, red or blue, and as a 
   fallback default case if none of these 3 specific tags are present in post:
 *     ```
       if ( jQuery('body').hasClass('single-post') {
         if ( jQuery('.tags-links a[href$="/tag/green/"]').length > 0 ) { 
           // JS code for green tag
         } else if ( jQuery('.tags-links a[href$="/tag/red/"]').length > 0 ) { 
           // JS code for red tag
         } else if ( jQuery('.tags-links a[href$="/tag/blue/"]').length > 0 ) { 
           // JS code for blue tag
         } else { 
           // JS code for all other tags
         }
       }
       ```
   
 * If you wish to include some external JS file depending on tag, it’s better to
   you code that functionality in your child theme.
 * Kind regards,
    Aleksandar

Viewing 1 replies (of 1 total)

The topic ‘adding different header codes, based on WP categories’ is closed to new
replies.

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

 * 1 reply
 * 2 participants
 * Last reply from: [Aleksandar Urošević](https://wordpress.org/support/users/urkekg/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/adding-different-header-codes-based-on-wp-categories/#post-9875083)
 * Status: not a support question