WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question

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 );
share|improve this answer
Thanks for the answer, @bungeshea. Any idea why this doesn't work for me? – Yoav Kadosh Jan 14 '13 at 7:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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