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.

When you add a text widget to a sidebar in Wordpress the widget includes this code

<div class="textwidget">

How do I remove this without editing the core?

FYI - I think this line is located here: wp-includes/default-widgets.php (line 383)

share|improve this question
    
Why would you want to do that? The widgets can have specific ID's. –  Wyck Jun 12 '12 at 16:31
    
I use a jquery box with some cool effects together with that text app, so the div messes up the css a bit. If there was an easy way to remove it it would save me alot of time :) –  Demilio Jun 12 '12 at 17:14
1  
Well the easiest way to remove it would be to use jquery's .remove. –  Wyck Jun 12 '12 at 17:34
    
And could you explain how? :) –  Demilio Jun 12 '12 at 22:28
    
Better using jQuery to remove a div after the fact that re-making a clean widget with the exact functionality you need? –  MZAweb Jun 13 '12 at 1:21
show 1 more comment

3 Answers 3

You can use output buffering (http://php.net/manual/es/book.outcontrol.php) to get the whole generated page in a variable and remove the offending before echoing.

But it seems overly complicated for this case. You can just copy all the widget code and create a new widget (in a plugin or your functions.php) without that hardcoded div. It's really not that much code.

Also, any reason to remove that div that can not be solved in css?

share|improve this answer
    
Why the downvotes? any better solution? –  MZAweb Jun 13 '12 at 1:20
add comment

As per the comment, in the case it is probably better to just remove or replace the class name using jQuery then a php function, since that class is hardcoded anyhow.

To remove it.

jQuery('.textwidget').remove();

To set the css to hide it.

jQuery('.textwidget').css('display', 'none');

To change the class name

jQuery('.textwidget').attr('class', 'newName');
share|improve this answer
    
This will probably remove the class right? But the problem here is the div –  Demilio Jun 16 '12 at 22:38
add comment

If you're looking to remove the actual div with the textwidget class applied to it but not it's content, this is a simple method using jQuery:

$('.textwidget').replaceWith($('.textwidget').contents());
share|improve this answer
add comment

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.