Wordpress: change the name of the sidebar widget dynamically

Is it possible to get the widget title that was included in my sidebar so that I can insert this as a name for my class attribute?

For instance: 'before_title' => <h2 class="title of the widget">',

If I will search element, I want to see: <h2 class="author">and <h2 class="links">etc.

thank

+3
source share
1 answer

This is definitely possible, but if you want to do it dynamically, you will need to use a filter.

The filter dynamic_sidebar_paramsshould work for you. If you are not familiar with what the filters do, basically the filter allows you to edit the content before it is displayed on the screen or save it to the database. More details here: http://codex.wordpress.org/Plugin_API/Filter_Reference

dynamic_sidebar_params ( print_r)

Array
(
    [0] => Array
        (
            [name] => Primary Widget Area
            [id] => primary-widget-area
            [description] => The primary widget area
            [before_widget] => <li id="search-2" class="widget-container widget_search">
            [after_widget] => </li>
            [before_title] => <h3 class="widget-title">
            [after_title] => </h3>
            [widget_id] => search-2
            [widget_name] => Search
        )

    [1] => Array
        (
            [number] => 2
        )

)

, , , $params, . , , , , .

:

function my_edit_widget_func($params) {
    $params[0]['before_title'] = '<h3 class="' . $params[0]['widget_name'] . '">' ;
    return $params;
}
add_filter('dynamic_sidebar_params', 'my_edit_widget_func');
+6

All Articles