0

I know this problem is pretty common at this moment and many people are asking the same question but for know I can't find any good solutions.

I wonder how i should implantate my scripts to wordpress?

This how far I have come:

function my_scripts_method() {
    wp_register_script("contact-form", get_bloginfo("stylesheet_directory") . "/form/contact-form.js");
    wp_enqueue_script("contact-form");
    wp_register_script("form", get_bloginfo("stylesheet_directory") . "/form/form.js");
    wp_enqueue_script("form");
    wp_register_script("validate", get_bloginfo("stylesheet_directory") . "/form/validate.js");
    wp_enqueue_script("validate");
    wp_register_script("answercheck", get_bloginfo("stylesheet_directory") . "/contact/answercheck.js");
    wp_enqueue_script("answercheck");
}

1 Answer 1

1

You've created a function my_scripts_method() and did you call it anywhere? Hooked it to something?

Try with

add_action( 'wp_enqueue_scripts', 'my_scripts_method()');

Also you can enqueue your scripts directly. So your

wp_register_script("contact-form", get_bloginfo("stylesheet_directory") . "/form/contact-form.js");
wp_enqueue_script("contact-form");

Will be

wp_enqueue_script("contact-form", get_bloginfo("stylesheet_directory") . "/form/contact-form.js");

If you have no dependencies. Also I'd use get_stylesheet_directory_uri() instead of your get_bloginfo("stylesheet_directory").

get_stylesheet_directory_uri()

EDIT

Try putting in your functions.php

add_action( 'wp_enqueue_scripts', 'my_scripts_method');

function my_scripts_method() {
    wp_enqueue_script('contact-form', get_template_directory_uri().'/form/contact-form.js','','', true);
    wp_enqueue_script('form', get_template_directory_uri().'/form/form.js','','', true);
    wp_enqueue_script('validate', get_template_directory_uri().'/form/validate.js','','', true);
    wp_enqueue_script('answercheck', get_template_directory_uri().'/contact/answercheck.js','','', true);
}

Alternatively you can put get_stylesheet_directory_uri() instead of get_template_directory_uri(), if it doesn't work. But it should (unless you don't have anything in the /form and /contact folders).

Sign up to request clarification or add additional context in comments.

9 Comments

This is what I got in my source code now. <script type='text/javascript' src='domain.com/wordpress/wp-content/themes/theme/form/…>
It still doesn't work unfortunately. This how I did in my funtions.php: add_action( 'wp_enqueue_scripts', 'my_scripts_method()'); wp_enqueue_script("contact-form", get_bloginfo("stylesheet_directory") . "/form/contact-form.js"); wp_enqueue_script("form", get_bloginfo("stylesheet_directory") . "/form/form.js"); wp_enqueue_script("validate", get_bloginfo("stylesheet_directory") . "/form/validate.js"); wp_enqueue_script("answercheck", get_bloginfo("stylesheet_directory") . "/form/answercheck.js");
See my edit, when you inspect the frontend, you should be able to see those scripts loaded in the inspector in the Sources tab. Or you should see some kind of an error.
I really appreciate your help. Unfortunately it still doesn't work. I can see that the script are linked in the source but still the java functions doesn't work.
If you can see them, then your problem is solved ;) You only asked how to put them in wordpress. Try putting the jquery dependancy on each one like this wp_enqueue_script('answercheck', get_template_directory_uri().'/contact/answercheck.js',array('jquery'),'', true);
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.