I’m a bit confused. I take advantage of https://github.com/idleberg/php-wordpress-vite-assets
for utilizing Vite’s belongings in my WordPress plugin.
I’ve used this:
public operate __construct() {
add_action('wp_loaded', [$this, 'testinit']);
}
public operate testinit() {
$basePath = plugin_dir_path( __FILE__);
$manifest = $basePath."dist/manifest.json";
$entryPoint = "index.js";
$viteAssets = new WordPressViteAssets($manifest, $basePath);
$viteAssets->addAction($entryPoint);
}
Within add_action
the script does this:
add_action('wp_head', operate () use ($entries) {
foreach ($entries as $entry) {
$scriptTag = $this->getScriptTag($entry);
However the script will not be included in my head. Once I name getScriptTag
initially, as a substitute of addAction
I get a tag…
Once I add a die
assertion earlier than the foreach, it isn’t referred to as. So plainly the motion for wp_head will not be fired. I attempted it additionally to make use of in my preliminary hook as a substitute of wp_loaded
different hooks like admin_init
, scripts_loaded
and so forth. But it surely appears I cannot name wp_head inside of those hooks.
Does anyone know why and the way I can resolve it?