Forums

[resolved] Widget from a plugin Error - "Cannot redeclare widget_myuniquewidget_register()" (2 posts)

  1. Trahald
    Member
    Posted 3 years ago #

    I'm trying to create my own test widget plugin like the example in Widget API, but after I activate the widget plugin and in wp-admin go to Appearance>Widgets, I get the error:

    "Fatal error: Cannot redeclare widget_myuniquewidget_register() (previously declared in /home/mycomput/public_html/test/wp-content/plugins/widgets.php:9) in /home/mycomput/public_html/test/wp-content/plugins/widgets.php on line 8"

    I'm using the code from the codex:

    function widget_myuniquewidget_register() {
          function widget_myuniquewidget($args) {
              extract($args);
          ?>
                  <?php echo $before_widget; ?>
                      <?php echo $before_title
                          . 'My Unique Widget'
                          . $after_title; ?>
                      Hello, World!
                  <?php echo $after_widget; ?>
          <?php
          }
          register_sidebar_widget('My Unique Widget',
              'widget_myuniquewidget');
    }
    add_action('init', widget_myuniquewidget_register);

    What am I doing wrong?

  2. Trahald
    Member
    Posted 3 years ago #

    Apparently the problem was actually just because I named my plugin file widgets.php, this for some reason causes a problem. Renaming the plugin file solved the issue.

Topic Closed

This topic has been closed to new replies.

About this Topic