Implementing Webflow JS in WordPress

Got it working. I had to add a couple more data attributes in the HTML markup to match those in the Webflow export. Then replace both the instances of window.$ with window.jQuery in webflow.js. An alternative to this to add var $ = jQuery at the beginning of that file. Now need to figure out … Read more

Removing auto versioning of JS and loading to header

If I’m reading correctly you just want to deregister a script but failed… I think that you tried to deregister it too early( before was added ). add_action( ‘wp_print_scripts’, ‘example’ ); function example() { wp_dequeue_script( ‘name_of_script’ ); } By calling the function in ‘wp_print_scripts’ should be fine, which is latter than ‘wp_enqueue_scripts’, where you usually … Read more

Where to upload JavaScript file in WordPress

Yes. You will want to enqueue your scripts using wp_enqueue_scripts and then upload them into your child theme. I normally create a /js/ directory to keep things organized. Here is a sample of how to enqueue a file inside of a themes JS subfolder. function wpse_enqueue_scripts() { wp_enqueue_script( ‘js-functions’, get_stylesheet_directory_uri() . ‘/js/functions.js’, array(‘jquery’), filemtime(get_stylesheet_directory() . … Read more

How to execute Javascript on a WordPress page?

<?php function enqueue_javascript_for_certain_page() { $page_id = 100; // change this to fit your needs if ( is_page( $page_id ) ) { // check the page you are on wp_enqueue_script( ‘my_script_name’, // script handle get_template_directory_uri() . ‘/js/my-js-file.js’, // script URI array( // your script is dependent on following: ‘jquery’, ‘jquery-ui’ ), NULL, // script version (NULL … Read more

I am trying to add current logged in user to my zoho chat

As Howdy_McGee said, you need to reference the individual data points, not the whole user object. <?php // Get the user object: username, email, firstname, lastname, displayname, and user ID $current_user = wp_get_current_user(); // Get other user meta, such as phone number // (you’ll have to check what meta_key you’re using for info like this) … Read more

How to include a JSON file on my page?

You can do this with PHP indeed. The steps are as followed; Get the contents of the JSON file within a variable using $json = file_get_contents(‘path-to-file.json’) Inside your <script> tags parse the JSON contents within a Javascript variable like this; var jsonContent=”<?= $json; ?>”; Debug the contents in your Javascript environment using the following; console.log(JSON.parse(jsonContent));

is_front_page() variable not found

There are several issues with your code. is_front_page() is a PHP function, you need to call it within <?php ?>. The script need to be printed in HTML in order to make it work. Try this.. function wpse_363853_run_on_front() { ?> <script> window.addEventListener(“load”, function() { <?php if( is_front_page() ){ ?> console.log(“front page”); <?php } ?> }); … Read more