How to Customize Your Instagram Feed's Mobile Layout with CSS and JavaScript
Content
One of the most common questions about the Smash Balloon Social Photo Feed plugin is how to control the number of columns on mobile devices. By default, the free version of the plugin displays a single column on mobile. Many users want a more integrated look, such as two or three columns, to better match their site's design on smaller screens.
Why This Happens
The plugin's default responsive behavior is designed to ensure images remain clear and legible on all devices. On mobile, it automatically switches to a single-column layout. This is a core feature of the free version. Customizing the number of columns for different screen sizes requires additional code to override the default styles and recalculate image heights.
Common Solutions
1. Using Custom CSS for Column Width
The first step is to use CSS media queries to change the width of the feed items on mobile. The following CSS code will force a two-column layout on screens smaller than 480px.
@media all and (max-width:480px) {
#sb_instagram.sbi_col_10 #sbi_images .sbi_item,
#sb_instagram.sbi_col_3 #sbi_images .sbi_item,
#sb_instagram.sbi_col_4 #sbi_images .sbi_item,
#sb_instagram.sbi_col_5 #sbi_images .sbi_item,
#sb_instagram.sbi_col_6 #sbi_images .sbi_item,
#sb_instagram.sbi_col_7 #sbi_images .sbi_item,
#sb_instagram.sbi_col_8 #sbi_images .sbi_item,
#sb_instagram.sbi_col_9 #sbi_images .sbi_item {
width:50% !important;
}
}
2. Adding JavaScript for Image Height
A frequent issue after applying the CSS is that the image height does not adjust proportionally, leaving large gaps. This happens because the plugin's JavaScript needs to recalculate the layout. Add the following code to the Custom JavaScript area in the plugin's settings (WordPress Dashboard > Instagram Feed > Customize > Custom JavaScript).
jQuery(window).resize(function(){
jQuery('#sb_instagram .sbi_photo').css('height', jQuery('#sb_instagram .sbi_photo').eq(0).innerWidth());
});
setTimeout(function(){
jQuery('#sb_instagram .sbi_photo').css('height', jQuery('#sb_instagram .sbi_photo').eq(0).innerWidth());
}, 500);
3. Combining CSS and JavaScript for a Complete Solution
For best results, use both the CSS and JavaScript snippets together. The CSS changes the layout, and the JavaScript ensures the images resize correctly. If the feed loads slowly, you can try adding a delay to the JavaScript, as shown in the code above.
Troubleshooting Tips
- Clear Caches: After adding new code, always clear any caching plugins or server-side caches to see the changes.
- Check for Conflicts: Your theme or other plugins might have CSS that conflicts with these changes. Use your browser's inspector tool to identify and override conflicting styles. In one case, a theme was forcing a 3-column layout with
width: 33.3% !important;which had to be overridden. - Ensure JavaScript is Loading: If the layout is still not adjusting, check that the plugin's JavaScript is loading correctly. You can try enabling the 'Enqueue JS in head' or 'Are you using an Ajax powered theme?' options under the Customize tab.
This community-driven approach has helped many users achieve their desired mobile layout. For more complex layout control, such as setting different column counts for tablet and mobile directly from the settings, the Smash Balloon team has developed that functionality for their Pro version.
Related Support Threads Support
-
mobilehttps://wordpress.org/support/topic/mobile-88/
-
Increase amount of desktop columnshttps://wordpress.org/support/topic/increase-amount-of-desktop-columns/
-
Change number of photos and columns in moiles and tabletshttps://wordpress.org/support/topic/change-number-of-photos-and-columns-in-moiles-and-tablets/
-
Mobile display, show 3 images in a linehttps://wordpress.org/support/topic/mobile-display-show-3-images-in-a-line/
-
Problems with Chttps://wordpress.org/support/topic/problems-with-c/
-
Mobile Versionhttps://wordpress.org/support/topic/mobile-version-92/
-
Mobile displayhttps://wordpress.org/support/topic/mobile-display-21/
-
responsive in landscape mode on mobilehttps://wordpress.org/support/topic/responsive-in-landscape-mode-on-mobile-2/
-
Columns stay fixed at 3https://wordpress.org/support/topic/columns-stay-fixed-at-3/
-
2 columns in mobilehttps://wordpress.org/support/topic/2-columns-in-mobile/
-
Display 2 columns on mobile viewhttps://wordpress.org/support/topic/display-2-columns-on-mobile-view-2/
-
Two columns on mobilehttps://wordpress.org/support/topic/two-columns-on-mobile/
-
Columns Layout and Translationhttps://wordpress.org/support/topic/columns-layout-and-translation/
-
Mobile column settinghttps://wordpress.org/support/topic/mobile-column-setting/
-
How to re-centre imageshttps://wordpress.org/support/topic/how-to-re-centre-images/
-
Can we change the width of the tiles, for mobile?https://wordpress.org/support/topic/can-we-change-the-width-of-the-tiles-for-mobile/
-
Two columns at smallest screen sizehttps://wordpress.org/support/topic/two-columns-at-smallest-screen-size/
-
columns in mobilehttps://wordpress.org/support/topic/columns-in-mobile-2/
-
Mobile version lookhttps://wordpress.org/support/topic/mobile-version-look/
-
Mobile Two Columnhttps://wordpress.org/support/topic/mobile-two-column/
-
Image Height Croppedhttps://wordpress.org/support/topic/image-height-cropped/
-
Two columns In mobile versionhttps://wordpress.org/support/topic/two-columns-in-mobile-version/
-
Mobile Viewhttps://wordpress.org/support/topic/mobile-view-49/
-
Desktop vs tablet vs mobile viewhttps://wordpress.org/support/topic/desktop-vs-tablet-vs-mobile-view/
-
Mobil wiewhttps://wordpress.org/support/topic/mobil-wiew/
-
Center Mode for carousel?https://wordpress.org/support/topic/center-mode-for-carousel/
-
Pro Version – Mobile Formathttps://wordpress.org/support/topic/pro-version-mobile-format/
-
Make it horizontalhttps://wordpress.org/support/topic/make-it-horizontal/
-
Columns on mobile device do not changehttps://wordpress.org/support/topic/columns-on-mobile-device-do-not-change/
-
Number of rowshttps://wordpress.org/support/topic/number-of-rows-2/
-
Mobile layouthttps://wordpress.org/support/topic/mobile-layout-8/
-
Number of Columnshttps://wordpress.org/support/topic/number-of-columns-21/