I am a bit confused. I use https://github.com/idleberg/php-wordpress-vite-assets for using Vite's assets in my WordPress plugin.

I have used this:

public function __construct() {
    add_action('wp_loaded', [$this, 'testinit']);

public function testinit() {
    $basePath = plugin_dir_path( __FILE__);
    $manifest = $basePath."dist/manifest.json";
    $entryPoint = "index.js";

    $viteAssets = new WordpressViteAssets($manifest, $basePath);

Inside of add_action the script does this:

add_action('wp_head', function () use ($entries) {
            foreach ($entries as $entry) {
                $scriptTag = $this->getScriptTag($entry);

But the script is not included in my head. When I call getScriptTag initially, instead of addAction I get a tag...

When I add a die statement before the foreach, it's not called. So it seems that the action for wp_head is not fired. I tried it also to use in my initial hook instead of wp_loaded other hooks like admin_init, scripts_loaded etc. But it seems I can not call wp_head inside of these hooks.

Does anybody know why and how I can solve it?

1 Answer 1


I figured it out - I need to use admin_head, because wp_head it not fired in the backend of WordPress.

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.