• Resolved malaiac

    (@malaiac)


    I have a plugin page …
    /wp-admin/admin.php?page=plugin.php

    in plugin.php :

    $title = __('My plugin page','plugin');
    $parent_file = 'plugin.php';
    wp_enqueue_script('admin-forms');
    require_once('admin-header.php');

    And still got no JS loading in the header…
    should be this one, like in edit.php :
    <script type='text/javascript' src='https://www.mydomain.com/wp-admin/js/forms.js?ver=20080401'></script>

    anyone got a clue why ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Because in plugin.php – it is way too late. The headers have already been written by the time plugin.php is included.

    The place to do this is in your plugin itself. I know that someone will have a better way but in general, I code a small function and hook it to admin_head – i.e.

    function adminStuff () {
         wp_enqueue_script('admin-forms');
         return;
    }
    add_action('admin_head','adminStuff');

    Then the js is loaded on every admin page. If you wanted to be neat about it – you could test for page = plugin.php in the function.

    Thread Starter malaiac

    (@malaiac)

    ok .. admin.php is loaded way before plugin.php… should have think of that.
    still an ugly solution: it loads forms.js for every admin page, even when not needed… let’s roll with it.

    Thanks !

    Then the js is loaded on every admin page. If you wanted to be neat about it – you could test for page = plugin.php in the function.

    Answers that problem too. Just test to see if your plugin page is being drawn before triggering your action.

    Thread Starter malaiac

    (@malaiac)

    actually, ‘admin_head’ is still too late.
    ‘admin_init’ did the job.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_enqueue_script does not load admin-forms in plugin page’ is closed to new replies.