Adding code to head to all pages manually

You might use the wp_head action, That is triggered within the section of the user’s template by the wp_head() function. add_action(“wp_head”, “hook_js”); function hook_js() { if(is_home() || is_front_page(){ $output=”<script> alert(‘Page is loading…’); </script>”; echo $output; } } Note that is better to add style and script with the action wp_enqueue_scripts and then enqueue and register … Read more

add onchange to select in a wp form

you can add any attribute to <select> using wordpress filter wp_dropdown_cats . wp_dropdown_cats filter allows you to modify the content of the taxonomy drop-down output. Try below code. function addAttributeToDropdown($html_content){ $html_content = str_replace(‘<select’,'<select onchange=”myFunc()”‘,$html_content); return $html_content; } add_filter(‘wp_dropdown_cats’,’addAttributeToDropdown’); add this inside your functions.php file

Adding a Calculator to a WordPress Page

You should look into creating a plugin for this and then inside of the plugin generating a shortcode for the output so you can place it almost anywhere you’d like inside wordpress. Having it has a plugin will give you the flexibility of quickly making changes and the future chance to apply it easily to … Read more

Add JavaScript to all WooCommerce Products

If you need to do this on the single product page use this condition then enqueue the JavaScript files. function enqueue_single_product_javascript() { if(is_product()) { // Use wp_enqueue_script() } } add_action(‘wp_enqueue_scripts’, ‘enqueue_single_product_javascript’); https://developer.wordpress.org/reference/functions/wp_enqueue_script/ https://docs.woocommerce.com/document/conditional-tags/

Adding Code into Theme Customizer Header

You use the customize_controls_enqueue_scripts action hook for that. Then you enqueue script as usual. Like this: function wpse256911_customizer_enqueue() { wp_enqueue_script( ‘my-customizer’, get_stylesheet_directory_uri() . ‘/js/my-customizer.js’, array( ‘jquery’, ‘customize-controls’ ) ); } add_action( ‘customize_controls_enqueue_scripts’, ‘wpse256911_customizer_enqueue’ );

Prevent update_checkout from firing mid-typing

It’s been a while and maybe you don’t need this information. But i am having exactly the same problem. So i have come up with this solution: window.setTimeout( function () { $(‘form.checkout’).off(‘input keydown change’, ‘.address-field input.input-text, .update_totals_on_change input.input-text’); }, 0); It removes all “input/keydown/change” events from zipcode and address fields. I have used setTimeout to … Read more