With the most recent release of my WordPress theme Cover, I’ve included an enhancement that I’m kind of proud of.
Cover supports a few modules in the Jetpack plugin, but the one I want to highlight is the infinite scrolling functionality.
The basic implementation of infinite scrolling support is simple enough:
add_theme_support( 'infinite-scroll', array(
/* options */
) );
With infinite scrolling, you’re never going to see the footer. This is a problem if you’ve got widgets in the footer, but fortunately the Jetpack team thought of this. They’re included an optional argument footer_widgets
which can tell whether or not a theme has footer widgets. If it does, it’ll switch the type from scroll
to click
.
Cover doesn’t use footer widgets — all the widgets go inside the overlay — but it does have the option of a footer social media menu. In the event of this menu’s existence, the infinite scrolling support needs to be aware enough to switch the type.
This is where the Jetpack-provided filter infinite_scroll_has_footer_widgets
comes in handy. Here is Cover’s implementation:
function cover_infinite_scroll_has_footer_widgets( $has_widgets ) {
$has_widgets = false;
if ( has_nav_menu( 'social_footer' ) ) {
$has_widgets = true;
}
return $has_widgets;
}
add_filter( 'infinite_scroll_has_footer_widgets', 'cover_infinite_scroll_has_footer_widgets', 10, 1 );
This way, it’s easy enough to detect the menu and indicate the type switch from scroll
to click
.
Leave a Reply