Pergunta

I have add an easy function filter in wordpress to add a class to a widget title by using the widget title as class and it works, but the title itself is not visible anymore afterwards.

What to add to this filter to show the title itself too, besides to the class outputting it does now?

function widget_title_as_class($title) { 
return '<div class="BlockHeader-text ' . sanitize_title($title) . '"></div>';
}
add_filter('widget_title', 'widget_title_as_class')

For instance: without filter firebug says this:

<div class="header-tag-icon">
<div class="BlockHeader-text"> Search </div>
</div>

With filter the output html says this:

<div class="header-tag-icon">
<div class="BlockHeader-text">
<div class="header-tag-icon Search"></div>
</div></div>

See the title is now a class but the title itself is gone? Must be easy to fix? Help me out PHP guys! Regards,

Foi útil?

Solução

function widget_title_as_class($title) { 
return '<div class="BlockHeader-text ' . sanitize_title($title) . '">'.sanitize_title($title).'</div>';
}
add_filter('widget_title', 'widget_title_as_class');

Because you are not passing value to the div

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top