• Greetings,

    I’m working on a plugin that requires some CSS and JS capabilities but only on the option page for the plugin. I followed the information found online regarding creating the options page …

    $page = add_options_page( ... )
    add_action("admin_head-" . $page, "example");

    … and created the example function as follows …

    function example() {
      wp_enqueue_script("prototype");
      wp_enqueue_script("my-js", WP_PLUGIN_URL . "/path/to/my.js", array("prototype"));
      wp_enqueue_style("my-css", WP_PLUGIN_URL . "/path/to/my.css);
    }

    … but neither the CSS nor the JS seem to get added to the document. What am I doing wrong? I know the function is executing through the use of a quick echo "Hi!"; statement from within example().

    Thanks,
    Dash

Viewing 1 replies (of 1 total)
  • Thread Starter David Dashifen Kees

    (@dashifen)

    I’ve somewhat solved this myself, though I’m not a fan of the solution. It’ll work well for now but I’d love to know if there’s a better way.

    Here’s my solution: load the scripts using admin_print_scripts-{plugin_page} and then enqueue the styles using admin_init. The code went something like this:

    add_action("admin_init", "add_styles");
    add_action("admin_menu", "add_options");
    
    function add_styles() {
      wp_enqueue_style( ... );
    }
    
    function add_options() {
      $page = add_options_page( ... );
      add_action("admin_print_scripts-" . $page, "add_scripts");
    }
    
    function add_scripts() {
      wp_enqueue_script("prototype");
      wp_enqueue_script("my-js", WP_PLUGIN_URL . "/path/to/my.js", array("prototype"));
    }
Viewing 1 replies (of 1 total)

The topic ‘admin-head-{plugin_page} actions’ is closed to new replies.