Snippets: Blog Grid Entry Custom Responsive Columns

/**
 * Add responsive grid settings to blog grid style entries
 * Note: Only add the classes you need. For example if the default columns
 * are set to 3 no need to define 3 columns again for tablet devices.
 *
 * All responsive column classes use the format span_1_of_{columns}_{device}
 * Devices: tl => tablet landscape ( max-width: 1024px )
 *			tp => tablet portrait ( max-width: 959px )
 *			pl => phone landscape ( max-width: 767px )
 *			pp => phone portrait ( max-width: 479px )
 *
 */
add_filter( 'wpex_blog_entry_classes', function ( $classes ) {

	$style = wpex_blog_entry_style();

	if ( 'grid-entry-style' == $style || 'grid' == $style ) {

		// 4 columns on tablet landscape
		$classes[] = 'span_1_of_4_tl';

		// 3 columns on table portrait
		$classes[] = 'span_1_of_3_tp';

		// 2 Columns on phone landscape
		$classes[] = 'span_1_of_2_pl';

		// 2 Column on phone portrait
		$classes[] = 'span_1_of_2_pp';

	}

	return $classes;

}, 40 );

Snippet Type: PHP

Posted Under: Blog

All PHP snippets should be added via a child theme's functions.php file.