I am trying to pass some widget options to an external script using wp_localize_script. I know how to pass the variables and how to use them within the script, but how do I extract the widget options to pass them as an array to the script? Here is what I have currently:

class WidgetName extends WP_Widget {
    public function __construct() {

        // load plugin text domain
        add_action( 'init', array( $this, 'widget_textdomain' ) );
        add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_scripts' ) );


    // This is what i'm having a problem with
    public function register_widget_scripts() {
        $options = get_option('widget-name');
        wp_localize_script('handle', 'obj-name', $options);

    // The rest of the widget code goes here

1 Answer 1


You can use the get_settings() member function:

public function register_widget_scripts() {
    $options = $this->get_settings();
    wp_localize_script( 'widget-name', 'obj-name', $options );
  • Thanks for the answer, @bungeshea. Any idea why this doesn't work for me? Commented Jan 14, 2013 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.