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'm attempting to dynamically create a text widget, add it to a named sidebar widget that my theme has already created ($sidebar_id = 'home-header-widget'), then populate the text widget with some preset content. I'm getting an error as indicated above at line 35 (commented below). Any ideas what I'm doing wrong?

Parse error: syntax error, unexpected '[' in C:....widgettest.php on line 35

Plugin Name: Widget Test

function cb_activate_widgettest(){

    $ops = get_option('widget_text');
    // find an $id that works...
    $ops[$id] = array(
      'title' => '',
      'text' => 'bar', // content?
    update_option('widget_text', $ops);

    $sidebar_id = 'home-header-widget';
    $sidebars_widgets = get_option('sidebars_widgets');
    $sidebars_widgets[$sidebar_id] = ["widget_text-$id"];  //this is line 35
    update_option('sidebars_widgets', $sidebars_widgets);

register_activation_hook(__FILE__, 'cb_activate_widgettest');
share|improve this question
up vote 3 down vote accepted

This part triggers it:

= ["widget_text-$id"]

Copy paste gone wrong or something? Square brackets used this way make no sense to PHP.

share|improve this answer

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.