Remove before_widget / after_widget content from Wp_Widget_Text

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.

Read More
// 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>

Related posts

Leave a Reply

2 comments

  1. 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.

  2. 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…