• 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)
  • Using a Child Theme, 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

    (@gussielotter)

    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>

    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.