How to Unregister Default WordPress Widgets from Your Theme

by • On Mar 25, 13 13:28pm, Updated: Feb 11, 14 14:28pm • 8147 Views

Every time when you install WordPress on your local server or on a web server, default WordPress theme and widgets gets activated automatically. Calendar, meta, pages etc. are some of the widgets which you would see after the initial WP installation. In most of the cases it would be visible on sidebar or on the right hand side of your site.

WordPress Tips and TricksHowever, even if you are changing the default theme with your newly purchased one, chances are there that it would also display the default widgets already activated on your sidebar or footer. Part of the reason behind this is most commercial themes gets these codes built in on sidebar even though they are widgetized.

In case if you are custom designing your own theme, you can easily turn them off by simply adding a snippet code on your theme’s functions.php file. WordPress has a function called “unregister widget” which can come into action in this case. Let’s take a look at the little demonstration code added here.
<?php
function unregister_default_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget'); }
add_action('widgets_init', 'unregister_default_widgets');
?>

I hope you would find this snippet very helpful.

Source: WordPress Codex.

You can follow us on Twitter, add on your Google+ circle or Like our Facebook page to get the latest news, updates and reviews.

advertisement

Comments