1

Some default widgets has automatic titles.

Is it possible to check if widget has automatic/inserted title using dynamic_sidebar_params filter?

4
  • 1
    I can tell you how to address the sample case but I am not sure there is a generic solution.
    – s_ha_dum
    Jun 10, 2015 at 22:41
  • Is there anything I can do with add_filter('widget_title', '')?
    – Ahmed Saad
    Jun 10, 2015 at 22:57
  • 1
    Yes, that is filter I was looking at but I can't write that code right now.
    – s_ha_dum
    Jun 10, 2015 at 23:03
  • Hope you write it soon. I appreciate your help.
    – Ahmed Saad
    Jun 10, 2015 at 23:12

1 Answer 1

2

Any widgets written to operate as the Core "Recent Posts" widget does can be forced to skip the title by a filter on widget_title:

function widget_title_hack_191120($title, $instance) {
  if (empty($instance['title'])) {
    $title = '';
  }
  return $title;
}
add_filter('widget_title','widget_title_hack_191120', 10, 2);

I don't know if there is a generic solution to the problem. Any widget could avoid this simply by not using the widget_title filter.

6
  • Thank you! This saved the day! Actually I tried this last night but I was getting Warning: Missing argument 2 for... error. Looks like I had to add priority to the filter.
    – Ahmed Saad
    Jun 11, 2015 at 6:24
  • Actually, I'm still getting this error for some widgets added by plugins.
    – Ahmed Saad
    Jun 11, 2015 at 7:38
  • 1
    I was very clear that this will work with widgets like the core ones but that I don't think there is a generic solution. I can write widgets in at least two ways that will get around this.
    – s_ha_dum
    Jun 11, 2015 at 13:15
  • Please do it. I need get this widgets thing done.
    – Ahmed Saad
    Jun 11, 2015 at 13:47
  • 1
    1) What is not clear about "there is no generic solution"? I can't write code to make this work with every widget out there. I said that from the beginning. I know at least two ways to write a widget that will make it difficult or impossible to hack the title the way you want. 2) You want me to fix errors caused by "some widgets added by plugins"? I don't even know what plugins are causing the issue and you want me to fix it? Does that even make sense to you? 3) I am here as a volunteer and that sounded like an order.
    – s_ha_dum
    Jun 11, 2015 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.