You can use the dynamic_sidebar_params
filter:
add_filter( 'dynamic_sidebar_params',
function( $params )
{
// target a sidebar id:
if( isset( $params[0]['id'] ) && 'sidebar-1' === $params[0]['id']
{
// target a widget name:
if( isset( $params[0]['widget_name'] ) && 'Text' === $params[0]['widget_name'] )
{
// target a widget id:
if( isset( $params[0]['widget_id'] ) && 'text-8' === $params[0]['widget_id'] )
{
// Append text to existing 'before widget' markup code:
if( isset( $params[0]['before_widget'] ) )
{
$params[0]['before_widget'] .= '<!-- Custom content -->';
}
}
}
}
return $params;
}
);
where the widget names are for example: Text, Categories, Calendar, … .
You can then modify it to your needs, for example the 'sidebar-1'
, 'Text'
and 'text-8'
parts.