Title: Adding Script to Button
Last modified: September 16, 2016

---

# Adding Script to Button

 *  [gussielotter](https://wordpress.org/support/users/gussielotter/)
 * (@gussielotter)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/adding-script-to-button/)
 * I am adding a pay button to my site, but there is some script with this button.
   When I load it directly into the HTML editor, it doesn’t work. Where do I need
   to add this script to make the button do what it’s supposed to? I can’t find 
   a plugin which is compatible with 4.5.4.

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

 *  [ThemeSumo](https://wordpress.org/support/users/themesumo/)
 * (@themesumo)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/adding-script-to-button/#post-8193663)
 * Using a [Child Theme](https://codex.wordpress.org/Child_Themes), you can include
   a JS file and add all of your custom JS code to this single file.
 * **Add this to the child theme functions.php file:**
 *     ```
       function my_custom_scripts() {
           wp_enqueue_script('my-custom-scripts', get_stylesheet_directory_uri() . '/scripts.js', array('jquery'));
       }
       add_action('wp_enqueue_scripts', 'my_custom_scripts');
       ```
   
 * Create a new file called **scripts.js** and place it within your child theme 
   folder.
 * **The contents of this JS file should look like this:**
 *     ```
       jQuery(document).ready(function($){
   
       // your scripts here
   
       });
       ```
   
 * Hope this helps.
 *  Thread Starter [gussielotter](https://wordpress.org/support/users/gussielotter/)
 * (@gussielotter)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/adding-script-to-button/#post-8205369)
 * Hi
 * Thanks for the reply. Let me just clarify – here is my script. Must I add it 
   to the JS file after the // or must I replace the whole line: // your scripts
   here
 * Sorry, not a javascript expert.
 * <script language=”JavaScript” type=”text/javascript”>
 * function click_30ef326adb4cf4078246ffe3f7e6c41c( aform_reference ) {
    var aform
   = aform_reference; aform[‘amount’].value = Math.round( aform[‘amount’].value*
   Math.pow( 10,2 ) )/Math.pow( 10,2 ); aform[‘custom_amount’].value = aform[‘custom_amount’].
   value.replace( /^\s+|\s+$/g,”” ); if( !aform[‘custom_amount’].value || 0 === 
   aform[‘custom_amount’].value.length || /^\s*$/.test( aform[‘custom_amount’].value)){
   alert ( ‘An amount is required’ ); return false; } aform[‘amount’].value = Math.
   round( aform[‘custom_amount’].value*Math.pow( 10,2 ) )/Math.pow( 10,2 ); }
 * </script>
 *  [CurtisK](https://wordpress.org/support/users/curtisk/)
 * (@curtisk)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/adding-script-to-button/#post-8354413)
 * Hi there
 * Don’t know if you found a solution yet.
 * I had the same problem. WordPress wraps the code in <p> which makes it unusable.
 * There’s a plugin called “Don’t muck my markup”. It works like a bomb.
 * It disables the auto-formatting.
 * Hope it helps.

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

The topic ‘Adding Script to Button’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [CurtisK](https://wordpress.org/support/users/curtisk/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/adding-script-to-button/#post-8354413)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
