This code will do what you’re after:
function my_between_widgets( $widget ) {
if ( is_admin() ) {
return;
}
// Get list of all sidebars and which widgets they have.
$sidebars_widgets = get_option( 'sidebars_widgets' );
// Check the position of the current widget in the widget area I want.
$position = array_search( $widget['id'], $sidebars_widgets['sidebar'] );
// If it's after the 3rd widget, do something.
if ( $position === 3 ) {
// Add code here.
}
}
add_action( 'dynamic_sidebar', 'my_between_widgets' );
You’ll need to replace the 'sidebar'
in $sidebars_widgets['sidebar']
with the actual name of the widget area you want to do this in though.
If you wanted to put it after every third widget or something, you’d just change $position === 3
to something checking if it’s divisible by 3, or whatever number you want.
Depending on what you’re doing though, it might be easier to just add the HTML you want as a 4th widget, and use :nth-child(4)
or nth-child(4n)
(for every 4th widget) in CSS to style it differently/clear floats etc.