How to change the widget HTML by a child WordPress theme

This is very simple and you can do it in this way:

add_filter('dynamic_sidebar_params', 'yourtheme_change_widget_head');

function yourtheme_change_widget_head( $params ) {
    if ( $params[0]['id'] === 'footer-sidebar-2' ) {
        $params[0]['before_title'] = '<h4 class="widget-title">';
        $params[0]['after_title'] = '</h4>';
    }
    return $params;
}

This filter allows you to check what is executed by dynamic_sidebar as parameter.
So first of all you need to check what is the sidebar you want to alter and later the parameter that you want to change.

Where to put it? In the functions.php of your child theme.

Liked it? Take a second to support Mte90 on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *

How to change the widget HTML by a child WordPress theme

time to read: <1 min
0