[resolved] admin_head and wp_enqueue_script (4 posts)

  1. Lutz Schröer
    Posted 7 years ago #

    I want to use jquery in my plugin's option page (the plugin itself does not need jquery). I could do this by simply adding a "wp_enqueue_script('jquery')" in my code. This works fine but unfortunately it also loads jquery everytime the blog is displayed and not only if the option page is loaded.

    To avoid this overhead I tried to load jquery the following way:

    function load_jquery() {
    add_action('admin_head', 'load_jquery');

    load_jquery() is executed but the jquery loading code does not appear in the head of the option page. Any ideas?

  2. Lutz Schröer
    Posted 7 years ago #

    Ok, answering myself :-):

    the solution seems to be totally different than I thought:

    if (is_admin())

    I don't know if this is the "correct" way but it seems to work.

  3. Roland Rust
    Posted 7 years ago #

    add_action('admin_print_scripts', 'your_function_calling_a_javascript');

  4. Lutz Schröer
    Posted 7 years ago #

    Thank you, works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic