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

Error – ‘create_function is deprecated’ [closed]

You no longer need to use create_function you can instead just use an anonymous function: add_action( ‘gform_preview_footer’, create_function( ”, ‘GFFormDisplay::footer_init_scripts(‘ . $form[‘id’] . ‘);’ ) ); Should be: add_action( ‘gform_preview_footer’, function() use ($form){ GFFormDisplay::footer_init_scripts($form[‘id’]); }); https://www.php.net/manual/en/functions.anonymous.php

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

How to generate the COOKIEHASH from JavaScript

By default it’s the MD5 hash of the site URL: $siteurl = get_site_option( ‘siteurl’ ); if ( $siteurl ) { define( ‘COOKIEHASH’, md5( $siteurl ) ); } This includes the scheme but not a trailing slash, so in your example you’d need the hash of https://zeth.dk. You can also override this by defining COOKIEHASH in … Read more

Implementing a simple slider in code?

First off, you shouldn’t insert <script> tags into WordPress’s template files. The proper way to add Javascript code is to use wp_enqueue_script(). If I’m reading this right, it appears you’re using jQuery code, so you’ll need to ensure that jquery is in the $deps array in your wp_enqueue_script() call. Also, WordPress uses jQuery in noConflict … Read more