Title: run javascript with in_category
Last modified: August 19, 2016

---

# run javascript with in_category

 *  [itmdesign](https://wordpress.org/support/users/itmdesign/)
 * (@itmdesign)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/run-javascript-with-in_category/)
 * Hi there, I want to use in_category to run a little javascript in only one of
   my categories. I’m using this code just above the </head> tag:
 *     ```
       <?php
        if ( have_posts() ) { the_post(); rewind_posts(); }
        if ( in_category(4) ) {
        echo "";
        }
        ?>
       ```
   
 * Once this works correctly I’ll put the javascript into the if statement. It currently
   puts the `<br />` in category 4 but it’s also doing it on the index.php page.
   I’m assuming this is because the index.php page is currently displaying posts
   from category 4, but how can I stop this from happeneing?
 * Thanks.

The topic ‘run javascript with in_category’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [itmdesign](https://wordpress.org/support/users/itmdesign/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/run-javascript-with-in_category/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
