Sticky Sidebar
Keeps the sidebar visible while visitors scroll through long posts on desktop screens, so your widgets and calls to action stay in view.
Opens WPIDE on
Code
@media (min-width: 1024px) {
#secondary,
.widget-area,
.sidebar {
position: sticky;
top: 2rem;
align-self: flex-start;
}
.admin-bar #secondary,
.admin-bar .widget-area,
.admin-bar .sidebar {
top: calc(2rem + 32px);
}
}
Notes
Works when the sidebar is shorter than the screen. Change the selector if your theme uses a different sidebar class.
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.