Title: Javascript in wordpress page, using child theme
Last modified: August 21, 2016

---

# Javascript in wordpress page, using child theme

 *  [cgonza](https://wordpress.org/support/users/cgonza/)
 * (@cgonza)
 * [13 years ago](https://wordpress.org/support/topic/javascript-in-wordpress-page-using-child-theme/)
 * Hi all.
    I’m trying to use some javascript that will display the day, on just
   one of my pages. Through wordpress I have included this directly on the page:
 *     ```
       <script type="text/javascript" src="/scripts/happydate.js"></script>
       <script type="text/javascript">
       <!--
       happydate();
       //--></script>
   
       I created a file named happydate.js with the code below and put in a scripts folder under my childtheme directory (wp-content/themes/childtheme/scripts):
   
       <script type="text/javascript">
   
             <!--
             // Array of day names
             var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
                     "Thursday","Friday","Saturday");
             var now = new Date();
             document.write("Happy " + dayNames[now.getDay()] + ".");
             // -->
   
           </script>
   
       I also tried adding both the codes below (separately, at different times) to my functions.php file (in the same childtheme directory). Neither of them worked for me. 
   
       <?php
       function add_my_scripts(){
       wp_register_script(‘happydate’,
       get_bloginfo(‘stylesheet_directory’).’/js/happydate.js’, array(‘jquery’),’1.0′);
       wp_enqueue_script(‘happydate’);
       }
       add_action(‘init’, ‘add_my_scripts’);
       ?>
   
       < ?php
       if ( !is_admin() ) { // instruction to only load if it is not the admin area
          // register your script location, dependencies and version
          wp_register_script('happydate',
              get_bloginfo('stylesheet_directory') . '/scripts/happydate.js',
              array('jquery'),
              '1.0' );
   
          // enqueue the script
          wp_enqueue_script('happydate');
       }
       ?>
       ```
   
 * _[Please be sure to use the code buttons when posting code – as is, your code
   may have been corrupted here]_
 * I have no idea where in the steps above I went wrong, or if all the syntax is
   correct. Any insight is appreciated. I have a little bit of a grasp on this stuff,
   but I’m definitely a newbie. Be gentle!
 * Thanks in advance.

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

 *  [David Choi](https://wordpress.org/support/users/wpthemes777/)
 * (@wpthemes777)
 * [13 years ago](https://wordpress.org/support/topic/javascript-in-wordpress-page-using-child-theme/#post-3733132)
 * About
 * > Through wordpress I have included this directly on the page:
 *     ```
       <script type="text/javascript" src="/scripts/happydate.js"></script>
       <script type="text/javascript">
       <!--
       happydate();
       //--></script>
       ```
   
 * Did you insert it directly into the page? The post edit text editor? If yes, 
   it won’t work, because any PHP or Javascript codes will be stripped out by WP.
   Instead, you can use a plugin like:
 * [http://wordpress.org/extend/plugins/per-post-scripts-and-styles/](http://wordpress.org/extend/plugins/per-post-scripts-and-styles/)
 * to insert the javascript codes for that page.
 *  Thread Starter [cgonza](https://wordpress.org/support/users/cgonza/)
 * (@cgonza)
 * [13 years ago](https://wordpress.org/support/topic/javascript-in-wordpress-page-using-child-theme/#post-3733228)
 * But it should be able to work without a plugin, by turning off the rich editor
   so it won’t strip out the src attribute I believe.
 *  [David Choi](https://wordpress.org/support/users/wpthemes777/)
 * (@wpthemes777)
 * [13 years ago](https://wordpress.org/support/topic/javascript-in-wordpress-page-using-child-theme/#post-3733243)
 * It has nothing to do rich editor turned on or off, because WP will parse the 
   content and strip out any PHP, JS, SQL codes due to security reasons, allowing
   anybody to inject malicious codes into your site (if users can post contents 
   on your site) is not a good idea.
 * You have to either insert those codes from functions.php, or using a plugin that
   allows inserting those codes. Try your luck in the WP repository
 * [http://wordpress.org/extend/plugins/search.php?q=insert+code](http://wordpress.org/extend/plugins/search.php?q=insert+code)
 *  Thread Starter [cgonza](https://wordpress.org/support/users/cgonza/)
 * (@cgonza)
 * [13 years ago](https://wordpress.org/support/topic/javascript-in-wordpress-page-using-child-theme/#post-3733257)
 * I will give this a shot. Thanks for your response.

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

The topic ‘Javascript in wordpress page, using child theme’ is closed to new replies.

## Tags

 * [child theme](https://wordpress.org/support/topic-tag/child-theme/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [cgonza](https://wordpress.org/support/users/cgonza/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/javascript-in-wordpress-page-using-child-theme/#post-3733257)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
