Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Problems with wp_enqueue_script in WordPress

I am quite new to WordPress and coding in general, so bear with me. I have two separate files of code one with all the php and another with all the JavaScript. I need the php to read the JavaScript but when I look in the console of the browser it can't find the file. It appears to be looking in the wrong folder so it won't find it anyways.

Here is the code that I have used to try get it to read the JavaScript file

function wpdocs_theme_name_scripts() {
    wp_enqueue_script( 'pq-forms-script', get_template_directory_uri() . '/pqnewsletterform.js', array(), '1.0.0', true );
} 

I've tried to change get_template_directory_uri to get_stylesheet_directory_uri but that did nothing.

Any suggestions on how to fix this problem would be much appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this code.

You need to use plugin_dir_url( __FILE__ ) instead of get_stylesheet_directory_uri.

function enqueue_scripts() {
  wp_enqueue_script( 'form-js', plugin_dir_url( __FILE__ ) . 'pqnewsletterform.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!