WordPress.org

Ready to get started?Download WordPress

Forums

Change widget title within Admin widgets panel (5 posts)

  1. mastermillo
    Member
    Posted 7 years ago #

    Hello there,

    actually I wanted to appear the widget title within the widget panel of the Admin Backend to have a better overview when working with a lot of widgets.

    I found a solution of Georg Leciejewski working for previous version of wp. As WordPress 2.2 has the widgets already included the structure changed and variables changed. So far this is not the big deal as the function wp_widget_draggable exists within the file /wp-admin/widgets.php (line 180)

    Therefore, I changed the variables of the original "title enhancements by GL" to wp 2.2 compliant variables starting with wp_ and added following lines within the file /wp-admin/widgets.php after (line 191) :

    // START 'Admin widget title enhancements' for wp2.2
    
    // Original Code of  widget titel enhancement by georg leciejewski
    // These lines are additional to wp 2.2 code
    // modification by mastermillo: changed $registered_widgets to $wp_registered widgets for wp 2.2 compliance
        if(!empty($wp_registered_widgets[$name]['params'])){
            $number = $wp_registered_widgets[$name]['params'][0];
            $options =get_option($wp_registered_widgets[$name]['classname']);
            $widgettitle=$options[$number]['title'] ;
        }else{
            $options =get_option($wp_registered_widgets[$name]['classname']);
            $widgettitle=$options['title'] ;
        }
        //show only if title is populated
        if(!empty($widgettitle)){
            $show_title= '<b>'.$widgettitle.'</b>';
        }
    // end widget title enhancements by georg leciejewski
    
    // original wp 2.2 codeline
    	/*
    	$output = '<li class="module" id="widgetprefix-%1$s"><span class="handle">%2$s</span></li>
    ';
    	*/
    	//added $show_title to see widget title within the admin area
    
    	$output = '<li class="module" id="widgetprefix-%1$s"><span class="handle"><small>[%2$s]</small> ' . $show_title . '</span></li>
    ';
    
    //END of 'Admin widget title enhancements' for wp 2.2
    
    	printf( $output, $sanitized_name, $wp_registered_widgets[$name]['name'] . $popper );
    }

    So far so good! The thing does what it should do, but actually I will get an Error Messeage when I reload the Admins Widgets Panel page within the area of Available Widgets!

    Warning: Illegal offset type in /home/www/.../wp-includes/functions.php on line 216
    
    Warning: Illegal offset type in /home/www/.../wp-includes/functions.php on line 221
    
    Warning: Illegal offset type in /home/www/.../wp-includes/cache.php on line 125
    
    Warning: Illegal offset type in /home/www/.../wp-includes/cache.php on line 131
    
    Warning: Illegal offset type in /home/www/.../wp-includes/cache.php on line 139
    
    Warning: Illegal offset type in /home/www/.../wp-includes/cache.php on line 144
    
    Warning: Illegal offset type in /home/www/.../wp-includes/functions.php on line 237

    Has somebody an Idea how to make these lines 100% compliant with WordPress 2.2?

    @ WordPress-Team
    What do you think about the idea to generally include this enhancement within WordPress 2.2 to make it more userfriendly?

    Thank you very much in advance for your support and greetings from Germany!

  2. bingorabbit
    Member
    Posted 6 years ago #

    Hello,

    I have managed to solve that in wordpress 2.3.1.

    In wp-includes/widgets.php at line 605, change
    $name = sprintf(__('Text %d'), $i);
    to:

    $title = $options[$i]['title'];
    $name = __('Text (' . $title . ')');

    this will change the text widget name for example from Text 1 to Text (Widget_Name) , and you can do that for example to the categories widget by doing the same change at line 792 from:
    $name = sprintf( __( 'Categories %d' ), $i );
    to:

    $title = $options[$i]['title'];
    $name = __('Categories (' . $title . ')');

    This really worked great for me..

    Hope that helps :)

  3. groucho
    Member
    Posted 6 years ago #

    that works, with the caveat that the title that appears as the widget title also appears on the web page. i want to put little 'badge' ads in text boxes so i can move them around easily, but i only want to see the title on the widget control panel - not on the web page.

  4. bingorabbit
    Member
    Posted 6 years ago #

    Obviously, the widget title has to appear in the web page, except if you need no title at all, and this is another situation that needs another solution..The one above is not for what you seek, sorry pal :)

  5. Doodlebee
    Member
    Posted 6 years ago #

    Groucho, you can still use bingo's solution. Just take it a step further. Around line 530 (in the same file), you'll see the wp_widget_text function. You want to look for:

    <?php echo $before_widget; ?>
    ...stuff here...
    <?php echo $after_widget; ?>

    Change that to:

    <h3 class="text_widget <?php echo $title; ?>">
    ...stuff here...
    </h3>

    Then you can style each title as needed. For example, if your title is "GoogleAd", then when you give it the name you want, the header will show up - only for that text widget - as <h3 class="text_widget GoogleAds">...

    Then you can add to the stylesheet:

    h3.GoogleAds {
    display:none;
    }

    And all of your text widgets - except for the GoogleAds one - will display the header tag for them.

    Hope that helps.

Topic Closed

This topic has been closed to new replies.

About this Topic