Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to take the text widget and remove the preceding / trailing markup from the text output currently showing as

<div class="textwidget">Test</div>

The before_widget / after_widget that is assigned with each widget area is under my control but the widget content itself is beyond me.

// Area 4, located in the footer. Empty by default.
    register_sidebar( array(
        'name' => __( 'First Footer Widget Area', 'lakeshoreautoclinic' ),
        'id' => 'first-footer-widget-area',
        'description' => __( 'The first footer widget area', 'lakeshoreautoclinic' ),
        'before_widget' => ' <p>',
        'after_widget' => '</p>',
        'before_title' => '<strong>',
        'after_title' => '</strong>',
    ) );

which outputs this for the surrounding / widget

<p><strong>Test</strong><div class="textwidget">Test</div></p>
share|improve this question
    
if there's an easier / shorter way to do this aside from creating a "new widget" > that would be ideal. –  Devise Sep 26 '11 at 1:46
    
Upvote since I'm trying to find this too. –  Jannemans Mar 23 '12 at 22:33

2 Answers 2

You have a couple options as I see it:

There's a the_widget() template tag that lets you control the before_widget and after_widget properties. However, it divorces the widget from the Widgets UI.

Alternately, you can try to accomplish whatever you're trying to do via CSS. If you change your before_widget line to this:

'before_widget' => '<p id="%1$s" class="widget %2$s">',

you'll get some classes and IDs that will make each widget style-able.

share|improve this answer

Text widgets formating can be found in '/wp-includes/default-widgets.php' starting from line 368. In order to remove that formating you would have to change line 382.

<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>

Just remove divs so you would have

<?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?>

However, that way you are changing wordpress core files, which means it might get changed in next updates, so better way to do it is copying the text widget class, renaming it (and the constructor), and adding it to your themes functions.php file (or a Plugin if you wish).

This is also a way to change position of widget name and so on...

share|improve this answer
1  
Hacking core is just a universally bad idea so not really a solution. –  mrwweb May 5 '12 at 23:10

Your Answer

 
discard

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.