Normal for scripts to be loaded after body tag?

This happens when something is incorrectly outputting markup within the head tag that should be inside the body tag. The browser rendering engine moves the body tag before whatever markup is incorrectly inserted. It looks like your #wrapper div is the likely culprit here and is being output in the wrong place.

How do I know if I should enqueue JS code or just include it in ONE PHP function?

Best practice in this case would be to enqueue the js file inside the WP functions.php file. Are the braintree submit pages on their own unique templates? If so you could add something like this to your functions file: function register_scripts() { if(is_page_template(‘template-parts/page-braintree.php’)): wp_register_script( ‘braintree-js’, get_template_directory_uri() . ‘/js/braintree.js’, array( ‘jquery’ ), false, true ); wp_enqueue_script( … Read more

Getting 404 in the Javascript

I think this is not good idea – create many enter points. Open Web Inspector and check your URL which using in JS code. But much better use the default admin_url( ‘admin-ajax.php’ ) to creates path which should be used in Java Script.

Issues trying to get an element by id

I didn’t get main part of your question. Still let me try: document.getElementById(‘InOrCm’).value = “in”; That mean you are adding value to the input with id “InOrCm”. If I am getting you then your syntax is right. Double check your ‘id’ name. check with console output. document.getElementById(‘InOrCm’).value = “in”; console.log(document.getElementById(‘InOrCm’).value); Here is second part: function … Read more

javascript not loading

Firstly, you don’t need to add scripts in footer.php manually. Secondly, if there are no script dependencies, you have to declare empty array: array(), rather than array(”). Due this mistake scripts are not loading except Bootstrap. The correct code is: function imk_scripts() { wp_enqueue_script( ‘bootstrap_js’, get_template_directory_uri() . ‘/js/bootstrap.min.js’, array(‘jquery’), ‘3.3.5’, true ); wp_enqueue_script( ‘plugin_js’, get_template_directory_uri() … Read more

How to integrate a JS fiddle?

You’re passing true as the $in_footer argument to wp_register_script(), but my_custom_js() is loading in the header. So doubleScroll is loading after the custom js. I would put my_custom_js() in a separate javascript file so you can control the dependencies. Create my_custom_js.js in the same place you have the double scroll script: jQuery(document).ready(function($) { $(“#double-scroll”).doubleScroll(); } … Read more

Where to paste Google Map Snippet / JavaScript / CSS for WordPress integration

The JS in the fiddle should be saved to a file, for example, scripts.js. If this was in a folder in the theme root called js you could enqueue the scripts like so: function add_wp_scripts() { wp_enqueue_script( ‘google-maps’, ‘https://maps.googleapis.com/maps/api/js’, array(), null, null ); wp_enqueue_script( ‘script’, get_template_directory_uri() . ‘/js/script.js’, array(), null, true ); } add_action( ‘wp_enqueue_scripts’, … Read more

WordPress wp_enqueue_script only adds text to top of page source

You need to wrap your text with <?php and ?>. Like this: <?php function my_scripts() { wp_enqueue_script( ‘jquery’ ); wp_register_script( ‘parallax’, get_template_directory_uri() . ‘/parallax.js’, array( ‘jquery’ ), NULL, true ); wp_enqueue_script( ‘parallax’ ); } add_action( ‘wp_enqueue_scripts’, ‘my_scripts’ ); ?> Otherwise, the PHP parser never sees it – and it’s sent as text to the browser. … Read more