Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created October 11, 2016 23:29
Show Gist options
  • Save GaryJones/24ee5cb078de4f4dea3c73a7e41a3484 to your computer and use it in GitHub Desktop.
Save GaryJones/24ee5cb078de4f4dea3c73a7e41a3484 to your computer and use it in GitHub Desktop.
Genesis: Add classes to footer widget areas container, depending on the configured number of footer widget areas.
<?php
add_filter( 'genesis_footer_widget_areas', 'gmj_add_footer_widgets_classes', 10, 2 );
/**
* Add classes to footer widget areas container, depending on the configured number of footer widget areas.
*
* @param string $output Existing footer widget areas container markup.
* @param int $footer_widgets Number of configured footer widget areas.
* @return string Possibly amended markup for footer widget areas container.
*/
function gmj_add_footer_widgets_classes( string $output, int $footer_widgets ): string {
$classes = [
'',
'col col-xs-12 center-xs',
'col col-xs-12 col-sm-6',
'col col-xs-12 col-sm-6 col-md-4',
'col col-xs-12 col-sm-6 col-md-3',
'col col-xs-6 col-sm-4 col-md-2',
];
array_walk( $classes, function( $class, $key ) use ( $output, $footer_widgets ) {
if ( $key === $footer_widgets ) {
return str_replace( 'widget-area"', $class . ' widget-area"', $output );
}
});
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment