Skip to content

Instantly share code, notes, and snippets.

@ollietreend
Created August 16, 2017 09:31
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 ollietreend/759d72b82c42c9178047500dff7b535a to your computer and use it in GitHub Desktop.
Save ollietreend/759d72b82c42c9178047500dff7b535a to your computer and use it in GitHub Desktop.
WordPress admin bar bump for Bootstrap fixed navbar
<?php
namespace MyTheme;
function setup() {
add_theme_support('admin-bar', ['callback' => __NAMESPACE__ . '\\admin_bar_bump']);
}
add_action('after_setup_theme', __NAMESPACE__ . '\\setup');
/**
* Admin Bar Bump
* WordPress adds margin to the html element when the admin bar is showing.
* We also need that margin on the navbar element, so we're tweaking
* the default styling to add it.
*/
function admin_bar_bump() {
ob_start();
_admin_bar_bump_cb();
$bump = ob_get_clean();
echo str_replace('html {', 'html, .navbar.fixed-top {', $bump);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment