Wordpress: How to apply a widget_title filter only to the widgets from a certain sidebar? Wordpress: How to apply a widget_title filter only to the widgets from a certain sidebar? wordpress wordpress

Wordpress: How to apply a widget_title filter only to the widgets from a certain sidebar?


Since you want to use a hardcoded sidebar name I assume perhaps you are creating a theme and have control over the code that prints the sidebar? If so, you could first add the filter and then remove it again, like this:

add_filter('widget_title', 'widget_title_empty');dynamic_sidebar('footer');remove_filter('widget_title', 'widget_title_empty');

This way, surrounding sidebars won't be affected.


If you're looking to remove the widget title only, you can do this without creating a custom function by passing "__return_false" as the argument to the filter:

add_filter('widget_title', '__return_false');dynamic_sidebar('footer');remove_filter('widget_title', '__return_false');

See http://codex.wordpress.org/Function_Reference/_return_false


I like Calle's answer better, but this will work if you don't have those conditions:

class Example {    protected $lastWidget = false;    public function __construct() {        add_filter('dynamic_sidebar_params', array($this, 'filterSidebarParams'));    }    /**    * record what sidebar widget is being processed    * @param array $widgetParams    * @return array    */    public function filterSidebarParams($widgetParams) {        $this->lastWidget = $widgetParams;        return $widgetParams;    }    /**    * check to see if last widget recorded was in sidebar    * @param string $sidebarName    * @return bool    */    public function isLastSidebar($sidebarName) {        return $this->lastWidget && $this->lastWidget[0]['id'] == $sidebarName;    }}$example = new Example();// in your widget's codeif ($example->isLastSidebar('footer-widget-area')) {    // you're in}