I am fairly new to wordpress and am trying to define and call a function but cannot get it to work.
The following code appears in a php file that is called from the
What you wrote is a Javascript function, it must be surrounded by in HTML code. Have you written your function in something like:
echo('');
Also, I think Wordpress must have some function ready to use to add scripts. Try to have a look on wp_enqueue_script (string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false);
edit: I just found that question, it may answer yours: How to write a Javascript function inside the functions.php of Wordpress?