1

I have a contact form that I would to place within my WordPress theme that pulls in specific Javascript AND CSS Files.

To pull in the Javascript (called x.js) is this correct? I tested it and it seems to work fine, I just want to see whether I've done this correctly!

Also - would I do exactly the same for a .css file?

Here's the php code I placed in the functions file:

add_action('wp_enqueue_scripts','contactform');
function contactform(){
if ( is_page_template('page-contact.php') ) {
    wp_enqueue_script('contact-javascript', 'js/x.js');
   }
}

Thanks for all help.

1 Answer 1

0

you need to give the part to the js/x.js file, the rest is correct.

6
  • Thanks. Can you explain what you mean by 'give the part' - do you mean that the Javascript Code must be in the 'x.js' file?
    – Henry
    Commented Jul 31, 2017 at 3:18
  • wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true ); like this get_template_directory_uri() . '/js/example.js', Commented Jul 31, 2017 at 3:21
  • thank you. Yes, I need to learn why that is applied...
    – Henry
    Commented Jul 31, 2017 at 3:22
  • get_template_directory_uri() gets the path to the file Commented Jul 31, 2017 at 3:24
  • Would it be exactly the same for .css? I mean to load a specific .css file for this template?
    – Henry
    Commented Aug 5, 2017 at 14:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.