How do I get my Javascript scripts working?

You must have to include wp_head() in header.php and wp_footer(); in your footer.php header.php <!DOCTYPE html> <html lang=”en”> <head> <meta charset=”UTF-8″> <title>Title</title> </head> <?php wp_head(); ?> <body> footer.php <?php wp_footer();?> </body> </html> if you do not add wp_head() AND wp_footer() WordPress hook does not fire using wp_enqueue_scripts hook .

Get related product based on subcategory selected from category id with ID 142

you can use this code or adapted to work for you case,, hope its work.. Add it to your function.php add_filter( ‘woocommerce_product_related_posts’, ‘woocommerce_get_direct_related_products’ ); function woocommerce_get_direct_related_products() { global $woocommerce, $product; // Related products are found from category $cats_array = array(0); // Get categories $terms = wp_get_post_terms( $product->id, ‘product_cat’ ); //Select only the category which doesn’t … Read more

Regenerating WordPress shortcodes based on value with AJAX

In order to change the shortcode value by leveraging ajax, you need to modify the PHP code and jQuery as mentioned below: function table_generator() { // Set product providers $providers = array( ‘Provider 1’, ‘Provider 2’, ‘Provider 3’, ); // Build provider selection form $output .= ‘<form id=”submitProvider” action=”” method=”POST”>’; $output .= ‘<select name=”provider_list”>’; $output … Read more

Install GTM in pure javascript through functions.php

The problem is that your code is inside the <head> element, but the code is trying to access document.body which won’t exist at the time that your script is run. If I recall correctly you’re supposed to place this code immediately after the opening <body> tag. To do this from functions.php your theme needs to … Read more

Get data from PHP to JavaScript to set position of each post on front page

You could output them as inline CSS custom properties instead of left/top, and then use those to set the position in either CSS or Javascript. PHP: <a class=”project” href=”https://wordpress.stackexchange.com/questions/345335/<?php the_permalink(); ?>” style=”—-x-position: <?php the_field(‘x’); ?>; —-y-position: <?php the_field(‘y’); ?>;'”> <p><?php the_field(“title”); ?></p> </a> CSS: .project { top: var(—-x-position); left: var(—-y-position); /* or CSS grid: */ … Read more

How to inherit custom javascript from parent to child pages?

Just define the function in its own separate JS file, and load that file alongside the page-specific files. The “WordPress way” would be to register the script containing the shared function(s) and then set it as a dependency of the other scripts: wp_register_script( ‘my-functions’, get_theme_file_uri( ‘js/functions.js’ ) ); if ( is_page( 1 ) ) { … Read more

Navigate through the posts using keyboard arrows

You’re using get_next_post and get_previous_post correctly with get_permalink. The next and prev functions either return a WP_Post object or a falsy value. The permalink function accepts either a post object or a valid post ID and returns the post url as string, if it was found, otherwise it returns boolean false. I tested the code … Read more