Skip to content

Instantly share code, notes, and snippets.

@smutek
Last active January 13, 2017 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smutek/8daf4ad06b4051f5278c793cd9dc9646 to your computer and use it in GitHub Desktop.
Save smutek/8daf4ad06b4051f5278c793cd9dc9646 to your computer and use it in GitHub Desktop.
Bootstrap 4 navigation accounting for Blade in Sage 9
<?php
namespace App;
// Add to functions, or to a dedicated controllers file
// Needs a global body class to hook into
/**
* Navigation arguments
*
* @param $data
*
* @return mixed
*/
function navControl( $data ) {
// Pass the walker class to a var, so it
// doesn't instantiate here.
$bootstrapWalker = 'wp_bootstrap_navwalker';
// Main Nav
$mainNavArgs = [
'theme_location' => 'primary_navigation',
'walker' => new $bootstrapWalker,
'menu_class' => 'navbar-nav mr-auto'
];
$data['mainNavArgs'] = $mainNavArgs;
return $data;
}
add_filter( 'sage/template/global/data', 'App\\navControl' );
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="{{ home_url('/') }}">{{ get_bloginfo('name', 'display') }}</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
@if (has_nav_menu('primary_navigation'))
{!! wp_nav_menu($mainNavArgs) !!}
@endif
</div>
</nav>
<?php
// In helpers.php, or whereveer makes the most sense to you
/*
* Add global body class to hook our data up to
*/
add_filter( 'body_class', function( $classes ) {
return array_merge( $classes, array( 'global' ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment