Title: Conditional statement for a template file
Last modified: August 20, 2016

---

# Conditional statement for a template file

 *  [miocene22](https://wordpress.org/support/users/miocene22/)
 * (@miocene22)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/conditional-statement-for-a-template-file/)
 * OK so I’m using a template file to have a page on my site that has an image scroller.
   This requires an external .js file for the code and an “onload” javascript statement
   to be added to the body tag.
 * 2 issues to overcome…
    I have enqued the external .js file the proper way from
   within functions.php. It would be more ideal to only enqueue it when this template
   file is used.
 * Also, I only want the “onload=…” to appear when the template file is used. My
   body tag is inside header.php which is called using get_header() from the template
   file. How can I ensure this?
 * One thing I tried was to set a variable that is the “onload=..” like so:
 *     ```
       <?php
       /*
       Template Name: My special template
       */
       ?>
       <?php $ScrollerFunc = 'onload="initHIS3()"'; ?>
       <?php get_header(); ?>
       ```
   
 * And then in header.php:
    `<body <?php body_class(); ?> <?php if ( isset($ScrollerFunc))
   echo $ScrollerFunc; ?>>`
 * But this doesn’t seem to work as it seems the variable $ScrollerFunc is not passed
   to/available to header.php.
 * Any ideas?

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/conditional-statement-for-a-template-file/#post-2654740)
 * In header.php check for the page (example Page ID = 42):
 *     ```
       $ScrollerFunc='';
       if(is_page( 42 )) {
       $ScrollerFunc = 'onload="initHIS3()"';
       }
       <?php body_class(); ?> <?php echo $ScrollerFunc; ?>>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/conditional-statement-for-a-template-file/#post-2654804)
 * you can also check for the page template:
 * [http://codex.wordpress.org/Function_Reference/is_page_template](http://codex.wordpress.org/Function_Reference/is_page_template)
 * uses the page template file name.

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

The topic ‘Conditional statement for a template file’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/conditional-statement-for-a-template-file/#post-2654804)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
