• Hello,
    I have a question for advanced developers.

    I’m struggling to understand how I can load a javascript file for a specific widget that I’m working on.

    Within the class of the widget I have the public function form( $instance ) {} that contains the fields of the widget.
    I have two selectors and I want to show the second selector based on the first selector.
    I’ve tested some simple selectors in my theme (with the js included and jquery) and it works.
    But it seems that adding this lines

    wp_register_script( ‘widget’, get_template_directory_uri() . ‘js/widget.js’, array(‘jquery’), ‘null’ );
    wp_enqueue_script(‘widget’);

    in

    public function form( $instance ) {}

    doesn’t load the js files properly, and the “selector thing” doesn’t work.

    I tried registering and enqueueing widget.js in functions.php, but obviously it doesn’t work because the selectors are in backend not frontend of wordpress.

    My questions is not about how to show the second selector based on the first selector.

    My question is how to load javascript in public function form( $instance ) {} ?
    What is the best way to load custom javascript for a widget in Dashboard > Widgets ?

    Thank you!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Load javascript in wp-admin/widgets.php’ is closed to new replies.