Where appears those widgets, in header, footer or sidebar? Can you send a screenshot and explain what exactly you want to do.
Website: http://mixmaking.we2host.lt/wordpress/
Widget 1 Widget 2 Widget 3
Html code here
Widget 4 Widget 5 Widget 6
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.
In what file i do i need to add that code?
And where do i put html code cause i dont see that u put something extra as ”test” in your code.
My widgets i use as widget 1 widget 2 widget 3 is ”text” widget so whats the name of those widgets, the third one?
The .css option didnt work it causes a bug.
-
This reply was modified 8 years, 9 months ago by
autox420.
Well i cant figger it out.