salcode / bootstrap-genesis

WordPress Genesis Child Theme setup to use Bootstrap, Sass, and Grunt
MIT License
184 stars 63 forks source link

Improving bootstrap-markup.php #134

Open bryanwillis opened 8 years ago

bryanwillis commented 8 years ago

So I've been thinking for awhile on how we could make bootstrap-markup.php.

This has been without question the most useful part of bootstrap-genesis to me, but I've felt limited with it in some ways. Mainly this is what I've struggled with...

Anyway, I made some changes here. I won't try to hide that php is not my strong suit and I'm sure it can be modified A LOT to be even more useful. The biggest thing this adds is the ability to quickly change classes with very limited code and at the same time it lets you add new classes that weren't previously defined in the $classes_to_add array.

For example let's say you create a custom page template. This is all that would be needed:

<?php
/**
* Template Name: New Classes Template
* Description: Example modifying page classes on the fly
*/

add_filter('bw_add_classes', 'bw_custom');
function bw_custom($classes) {
    $classes = array( 
        'nav-secondary'  => 'navbar navbar-default navbar-static-top nav-blue',
        'entry'          => 'panel panel-default',
    );
    return $classes;
}

genesis();

This has become incredibly convenient for me especially since I can add new classes like entry in the above example. There are tons of attributes to add classes to in Genesis.

This also would encourage people to not have to edit core genesis files as much since we can purely use filters. We also don't have to add the filter since it will automatically be added to the array.

It's easy to add additional attributes in Genesis and this would allow us to modify them easier

echo genesis_attr( 'custom-section' );
sprintf( '<div %s>', genesis_attr( 'custom-section' ) );
printf( '<div %s>', genesis_attr( 'custom-section' ) );

Anyway, I'm sure there's things wrong with my code and it can be improved upon... let me know what you think of this idea.