The difference between Filter and Old method

I’m getting several questions what the difference is between the Filter and the Old method used in Dynamic Widgets. Both methods has its advantages and disadvantages. Which method works best for you is something for you to decide. However, I’d recommend not touching the method option, so using the (default) Filter method, when you start using this plugin and see how it performs.

The Filter method controls the widgets before a sidebar is rendered by WordPress. When a sidebar becomes empty (and there are no default widgets set by the theme), the sidebar will not be rendered by WordPress, leaving nothing behind. This is particular very usefull when your theme uses for example a border around the sidebar. Disadavantage of this method is, it has to process all applicable widgets for every sidebar it comes across during the time the page is rendered. When you have many sidebars and/or many options set for the widgets this might slow down the rendering significant.

The Old method controls the widgets at the moment the sidebars are rendering. It deletes the widgets from the sidebar. This can leave you behind with a rendered empty sidebar. When your theme is using borders around it, it will be noticeable, otherwise probably not. This method is faster as the processing is done only once for all sidebars together. This is very useful for users who have many sidebars and/or widgets.

Now what if you have many sidebars and/or widgets, you notice a significant slow down of rendering and also a theme which uses borders around sidebars? Both methods are not really usable at that point. Well, there is a way, but that needs some hacking in your theme involved. You should have some PHP programming expierence before you would ever think about this. You use the Old method for this hack and the PHP output buffering functions. You have to find in your theme files where the sidebar is called. At that point you replace the following example PHP code. Please note this PHP code needs to be adapted to the theme you are using. You can’t just copy – paste! I’m not responisble for any damage caused.

ob_start();
$success = dynamic_sidebar($index);
$content = ob_get_clean();
if ($success) {
  do_output_div($content);
}

When you use the since WordPress 3.0 standard Twenty Ten theme, you should have a look to WP Weaver (also used here) which has this piece of code adapted and other nice features added to this standard theme.