Skip to content

Instantly share code, notes, and snippets.

@PeterBooker
Last active August 29, 2015 14:17
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 PeterBooker/55048729ab968a161953 to your computer and use it in GitHub Desktop.
Save PeterBooker/55048729ab968a161953 to your computer and use it in GitHub Desktop.
Foundation 5 Top Bar Custom Menu Walker for WordPress
<?php
/*
* Provide fallback output incase no Menu is selected.
*/
public static function fallback( $args = array() ) {
/*
* No content for left side Fallback
*/
if ( 'left' == $args['menu_class'] ) {
echo "<ul class=\"left\"></ul>";
return;
}
$home_url = site_url( '/' );
$admin_menu_url = admin_url( '/nav-menus.php' );
$output = "<ul class=\"right\">\n";
$output .= "<li class=\"menu-item\">\n";
$output .= "<a href=\"{$home_url}\">Home</a>\n";
$output .= "</li>\n";
if ( current_user_can( 'manage_options' ) ) {
$output .= "<li class=\"menu-item\">\n";
$output .= "<a href=\"{$admin_menu_url}\">Customise Menu</a>\n";
$output .= "</li>\n";
}
$output .= "</ul>";
echo $output;
}
<?php
/*
* Fixed TopBar + WP Admin Bar Fix
*/
public static function fixed_fix() {
if ( ! is_admin() && is_admin_bar_showing() ) {
remove_action( 'wp_head', '_admin_bar_bump_cb' );
$height = WP_TopBar_Walker::$height;
$output = '<style type="text/css">' . "\n\t";
$output .= 'body.admin-bar #wpadminbar { position: fixed; }' . "\n\t";
$output .= 'body.admin-bar .fixed { margin-top: 46px; } body.admin-bar .fixed + div { margin-top: ' . $height . '; } body.admin-bar .fixed.expanded { margin-top: 0; }' . "\n\t";
$output .= '@media ( min-width: 782px ) { body.admin-bar .fixed { margin-top: 32px; } body.admin-bar .fixed + div { margin-top: ' . $height . '; } body.admin-bar .fixed.expanded { margin-top: 0; } }' . "\n\t";
$output .= '</style>' . "\n";
echo $output;
}
}
<?php
/*
* Filter Menu Args relevant for this Walker
*/
public static function menu_args( $args ) {
if ( $args['walker'] instanceof WP_TopBar_Walker ) {
$args['container'] = false;
$args['fallback_cb'] = 'WP_TopBar_Walker::fallback';
}
return $args;
}
<?php
/*
* Sticky TopBar + WP Admin Bar Fix
*/
public static function sticky_fix() {
if ( ! is_admin() && is_admin_bar_showing() ) {
remove_action( 'wp_head', '_admin_bar_bump_cb' );
$output = '<style type="text/css">' . "\n\t";
$output .= 'body.admin-bar #wpadminbar { position: fixed; }' . "\n\t";
$output .= 'body.admin-bar { padding-top: 46px; }' . "\n\t";
$output .= 'body.admin-bar .sticky.fixed { margin-top: 46px; }' . "\n\t";
$output .= '@media ( min-width: 782px ) { body.admin-bar .sticky.fixed { margin-top: 32px; } }' . "\n\t";
$output .= '@media ( min-width: 782px ) { body.admin-bar { padding-top: 32px; } }' . "\n\t";
$output .= '</style>' . "\n";
echo $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment