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

108
Views
Why JS alert message is not fired when in class

I am learning wordpress plugin development. I have dummy question - Why, the alert message is not fired, when located in js class or in index.js?

I created new file "test.php" in my plugin folder

<?php
/*
Plugin Name: Test
Description: test plugin
Version: 1.0
Author: Jarda

*/


class Test{

    function __construct(){
add_action('wp_enqueue_scripts', array($this, 'startMyScripts'));
    }

    function startMyScripts(){
        wp_enqueue_script( 'testScript', plugin_dir_url( __FILE__ ) . '/src/index.js' );
    }
    
    $test = new Test();
}

Than I created js file "index.js" in /src/

import Search from "./modules/Search"
const search = new Search()

And a class "Search" in /src/modules

    class Search{
    constructor(){
    alert("helo")
    console.log("fired")
    }
}

export default Search

I have node installed, package.json file looks like this

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "wp-scripts build",
    "start": "wp-scripts start",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@wordpress/scripts": "^23.5.0"
  }
}
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Ok, so the path must be wp_enqueue_script( 'testScript', plugin_dir_url( FILE ) . '/build/index.js' );

about 4 years ago · Santiago Gelvez 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!