WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Load jQuery in Plugin Options Page (6 posts)

  1. rpophessagr
    Member
    Posted 4 years ago #

    I'm trying to load jQuery into a plugin options page and having a dickens of a time doing so... any tips would be welcome.

    I tried:

    add_action('admin_init', 'add_jQuery'));
    
    function add_jQuery(){
        	wp_enqueue_script('jquery');
    }

    didn't work.... any help would be most welcome.

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    JQuery should already be running in the admin area.

  3. rpophessagr
    Member
    Posted 4 years ago #

    firebug is saying that it's not.

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    Ok, first look at how you're adding your plugin page, eg.

    add_dashboard_page( 'page_title' , 'menu_title' , 'manage_options' , 'plugin_handle' , 'callback_function' );
    add_posts_page( 'page_title' , 'menu_title' , 'manage_options' , 'plugin_handle' , 'callback_function' );

    It's the handle you need, so you can add actions to that page specifically, using the two examples above the page hook would be the following respectively..

    dashboard_page_plugin_handle
    posts_page_plugin_handle

    The easiest way to get the hook/handle is to store it when you add the page, eg..

    $plugin_hook = add_posts_page( 'page_title' , 'menu_title' , 'manage_options' , 'plugin_handle' , 'callback_function' );

    So you can then do..

    add_action( "admin_print_scripts-$plugin_hook" , 'my_enqueue_func' );

    or

    add_action( "admin_head-$plugin_hook" , 'my_enqueue_func' );

    or

    add_action( "load-$plugin_hook" , 'my_enqueue_func' );

    Hope that helps..

  5. rpophessagr
    Member
    Posted 4 years ago #

    Perfect!

    Thank you!

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    You're welcome.. :)

Topic Closed

This topic has been closed to new replies.

About this Topic