How can I load certain JavaScripts only on blog pages?

Properly enqueue the scripts, via callback hooked into the appropriate hook Use contextual conditional tags to determine when to enqueue For example, you’d do something like: function wpse135482_enqueue_scripts() { // Only enqueue this script on single post pages if ( is_singular( ‘post’ ) ) { wp_enqueue_script( $args ); } } add_action( ‘wp_enqueue_scripts’, ‘wpse135482_enqueue_scripts’ ); Further … Read more

How to install cool javascript feature in WordPress?

I’m not sure I fully understand, but this isn’t the recommended way to load js in WordPress. You normally would load scripts using a special WordPress function in your theme’s functions.php file. It’s wp_enqueue_script(). More here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script By the way, WP also has its own function that essentially is used where you might use include(). … Read more

How to use Readmore.js? [closed]

The problem is related to wordpress loading jquery in noconflict mode in which the $ shortcut does not work. Try to replace it with an explicit jQuery or wrapt the relevant code in a way which will decalre $ like in the following example jQuery(document).ready(function ($) { $(‘article’).readmore(); });

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 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’ );