Reputation: 23
When creating a widget, WordPress puts a <div class="typewidget">
around the widget.
I want to remove these extra divs without editing the wp-includes/default-widgets.php
file.
In my theme index.php
file, I use:
<ul>
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('widgetname') ) : ?>
<?php endif; ?>
</ul>
Then, in the functions.php
file:
register_sidebar(array(
'name' => 'widgetname',
'before_widget' => '<li>',
'after_widget' => '</li>',
));
And this shows in the site:
<ul>
<li>
<div class="textwidget">
<strong><a href="#">musica</a></strong> <a href="#">Lorem ipsum dolor sit amet dolor sit am.</a>
</div>
</li>
</ul>
Any ideas? Thanks.
Upvotes: 0
Views: 4887
Reputation: 23
A friend just helped me out and I fixed this.
After loading jQuery:
var cnt = $(".textwidget").contents()
$(".textwidget").replaceWith(cnt);
Where .textwidget
is the class in the extra div. It varies according to each type of widget in WordPress.
Upvotes: 1
Reputation: 11895
what about using something like:
var stuff = document.getElementsByTagName("div");
for (i=0, i<stuff.length, i++) {
if (stuff[i].className=='typewidget') {
var stuff_in_div = stuff[i].innerHTML;
stuff[i].parentNode.innerHTML=stuff_in_div;
}
}
seems like this might work. What do you think?
Andy
Upvotes: 0
Reputation: 11895
something like the following might work.
var stuff_in_div = document.getElementById("typewidget").innerHTML;
stuff_in_div.parentNode.removeChild("typewidget");
and then if you give the < li > an id like "target", you could just shove stuff_in_div in there with:
document.getElementById("target").innerHTML = stuff_in_div;
Does this seem reasonable?
Andy
Upvotes: 0