Keep the Last Sidebar Widget in View
Makes the last widget in the sidebar stick to the top of the screen while the visitor scrolls long posts, a good spot for a newsletter form or ad.
Opens WPIDE on
Code
@media (min-width: 1024px) {
#secondary .widget:last-child,
.widget-area .widget:last-child,
.sidebar .widget:last-child {
position: sticky;
top: 2rem;
}
.admin-bar #secondary .widget:last-child,
.admin-bar .widget-area .widget:last-child,
.admin-bar .sidebar .widget:last-child {
top: calc(2rem + 32px);
}
}
Notes
Only applies on screens wider than 1024 pixels. Adjust the selectors if your theme uses different sidebar classes.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.