Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Why do widgets get automatically added to a widget area? WordPress

Hello and thanks for the help.

I just built a comercial theme and whenever I run a clean WP install, upload and activate it I get a series of widgets that get automatically added to my front page sidebar(Search, Recent Posts, Recent Comments, Archives, Categories, and Meta).

Here's the code for the widget area:
<aside id="sidebar" class="col span_4 clr">

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Frontpage Sidebar')) : else : ?>

<h1>Frontpage Widgets</h1>
<p>There are several custom widgets that were specifically built for this area. Please see documentation for instructions.</p>

<?php endif; ?>

</aside><!-- sidebar -->


And here's the code from the functions file:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Frontpage Sidebar',
'description' => 'This widget area appears to the right of the slider on the front page.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div><!-- widget_entry --></div><!-- widget -->',
'before_title' => '<h1>',
'after_title' => '</h1><div class="widget_entry">'
));
}


I don't agree with widget being added automatically so I need prevent them from appearing during the install as it breaks the layout.

Regards,
Denis

Answers (7)

2012-08-03

Michael Caputo answers:

Try:

<?php if (dynamic_sidebar('Frontpage Sidebar')) ; ?>


Denis Leblanc comments:

Thanks Micheal,

Would I use this on the front page or when registering the widget area in the functions file/

d.


Michael Caputo comments:

Wherever your widget area should go. So your code should be:


<aside id="sidebar" class="col span_4 clr">


<?php if (dynamic_sidebar('Frontpage Sidebar')) : else : ?>

<h1>Frontpage Widgets</h1>
<p>There are several custom widgets that were specifically built for this area. Please see documentation for instructions.</p>

<?php endif; ?>

</aside><!-- sidebar -->


Denis Leblanc comments:

Micheal,

Tried the code you provided, dropped everything in my database and ran the install again. Same thing happened, just loaded a bunch of widgets automatically.

Do you think those widgets might be getting loaded from the default Twenty Eleven theme?

d.


Michael Caputo comments:

Disregard my previous posts - I misunderstood your question.

To my knowledge, the widgets are automatically added when you install your site. You'd need a modified version of Wordpress to disable this function.

My suggestion would be to try grabbing this copy of Wordpress: http://wordpress.org/wordpress-3.4.1-no-content.zip
And adding your own wp-content folder.

I dont know for sure, but the "no-content" build of wordpress may not contain these widgets.

Again: I haven't tested this but it's worth a shot.


Denis Leblanc comments:

That's what I figured. I'll be reselling this theme so I can't start telling my customers to install a particular version of WP without content so I was hoping for some kind of function that would disable those widgets upon theme activation or something of the sort.

Thanks for your help.

d.

2012-08-03

Jatin Soni answers:

I believe you are not calling this widget on front page and it got different widget. Check in Dashboard -> widget if you can find same widgets anywhere than see or check your front page with something code like <?php get_sidebar(); ?> and check which sidebar has been set there.


Denis Leblanc comments:

Jatin,

I'm positive that I'm loading the proper sidebar on the front page(see attached screenshot), and the code is as mentioned above.

d.