Title: Include Code If Certain Class is Displayed
Last modified: August 20, 2016

---

# Include Code If Certain Class is Displayed

 *  [Connor Crosby](https://wordpress.org/support/users/ccmovies/)
 * (@ccmovies)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/include-code-if-certain-class-is-displayed/)
 * I am making a theme and I want to display javascript only if a certain class 
   is showing on the page. That way it doesn’t load every time. How can I do this?
   I am not very good with PHP so if you could spell it out, that would be great!!
   😀

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/include-code-if-certain-class-is-displayed/#post-2407757)
 * > only if a certain class is showing on the page.
 * where is that class coming from?
 * is that an output from `body_class()` or so?
 * or how else could you define the pages, where you want to load the js script?
 *  Thread Starter [Connor Crosby](https://wordpress.org/support/users/ccmovies/)
 * (@ccmovies)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/include-code-if-certain-class-is-displayed/#post-2407758)
 * I have an image slider and I only want the js to load if the class “slider” is
   on the page.
 * Although, I only plan on having it on the homepage, so maybe the `body_class()`
   as well.
 * Thanks!
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/include-code-if-certain-class-is-displayed/#post-2407767)
 * conditional tags [http://codex.wordpress.org/Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)

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

The topic ‘Include Code If Certain Class is Displayed’ is closed to new replies.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [id](https://wordpress.org/support/topic-tag/id/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 3 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/include-code-if-certain-class-is-displayed/#post-2407767)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
