php - How do I include a javascript file in Wordpress admin Widgets -


i have created widget wordpress. form of widget has input boxes. now, want add custom input box uses javascript file downloaded http://jscolor.com/

now, problem is, not working. have registered javascript file in form function of wp_widget class.

require_once('index.php'); add_action('admin_enqueue_scripts', 'pw_load_scripts'); 

the pw_load_scripts function in index.php

function pw_load_scripts() {     wp_register_script('custom-js', plugin_dir_url(__file__).'scripts/jscolor.js');     wp_enqueue_script('custom-js'); } 

after these, not working. correct way task?

my error.log has error

[mon oct 07 21:37:30.591896 2013] [:error] [pid 14853] [client 127.0.0.1:42453] php fatal error:  cannot redeclare _wp_menu_output() (previously declared in /var/www/wordpress/wp-admin/menu-header.php:36) in /var/www/wordpress/wp-admin/menu-header.php on line 36 

thank you

the correct hook admin_print_scripts 1 enqueue styles and scripts.

note admin_footer , admin_head accept same screen targeting 'actionname-$hook':

add_action( 'admin_print_scripts-widgets.php', 'admin_enqueue_so_19228543' );  function admin_enqueue_so_19228543() {     wp_enqueue_script(              'my-script',              plugins_url( '/my-script.js', __file__ ),              array(), // dependencies             false, // version             true // on footer     );     wp_enqueue_style(          'my-style', plugins_url( '/my-style.css', __file__ )      );  } 

1 codex saying otherwise, pretty sure official stance. i'm researching , report back.


update

i cannot find reference admin_print_scripts being correct hook, although works , i've seen used way many times. completeness, how admin_enqueue_scripts works:

add_action( 'admin_enqueue_scripts', 'admin_enqueue_so_19228543' );  function admin_enqueue_so_19228543( $hook ) {     if( 'widgets.php' != $hook )         return;      wp_enqueue_script(              'my-script',              plugins_url( '/my-script.js', __file__ ),              array(), // dependencies             false, // version             true // on footer     );     wp_enqueue_style(          'my-style', plugins_url( '/my-style.css', __file__ )      );  } 

related: difference between do_action('admin_enqueue_scripts', $hook_suffix) , do_action(“admin_print_styles-$hook_suffix”) syntax


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -