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

My Button Default Click Is Not Working In WordPress Using Javascript Code

Anytime you want to use JavaScript in WordPress, you should enqueue it. Save the JS as a file, ie clickbutton.js inside your theme folder: document.getElementById(“defaultOpen”).click(); Then in functions.php, enqueue that file: add_action(‘wp_enqueue_scripts’, ‘wpse_371294_enqueue_js’); function wpse_371294_enqueue_js() { wp_enqueue_script(‘click-button’, get_template_directory_uri() . ‘/clickbutton.js’, array(”), “1.0”, true); } (If you only need the file to run on one page, … Read more

Change background image based on the hour [closed]

This question isn’t WordPress specific so is perhaps better for StackOverflow instead. We can make it WordPress specific by suggesting the use of wp_enqueue_script to add the script to the page, but ultimately this is a JavaScript question. I’m basing my answer off of this article // Get the local time of the visitor var … Read more