Skip to content

Instantly share code, notes, and snippets.

@mirkoschubert
Created December 12, 2019 11:06
Show Gist options
  • Save mirkoschubert/80a7bc81e785ff482f57916a61424d74 to your computer and use it in GitHub Desktop.
Save mirkoschubert/80a7bc81e785ff482f57916a61424d74 to your computer and use it in GitHub Desktop.
Divi 4 Theme Builder Hack for Fixed Navigation Bars
/**
* Custom Body Class for Child Theme
*/
function divi_child_body_class( $classes ) {
$classes[] = 'child';
return $classes;
}
add_action( 'body_class', 'divi_child_body_class' );
/**
* Fixed Body Class for Theme Builder Header
*/
function divi_child_tb_fixed_body_class( $classes ) {
$has_tb_header = in_array( 'et-tb-has-header', $classes );
$is_fixed_header = 'on' === et_get_option( 'divi_fixed_nav', 'on' );
if ($has_tb_header) {
if ($is_fixed_header) {
$classes[] = 'et_fixed_nav';
} else {
$classes[] = 'et_non_fixed_nav';
}
$classes[] = 'et_show_nav';
unset($classes[array_search('et-tb-has-header', $classes)]);
}
return $classes;
}
add_filter( 'body_class', 'divi_child_tb_fixed_body_class');
/**
* Set Layout ID for the Main Header
*/
function divi_child_set_layout_id( $layout_id, $post_type ) {
if ($post_type === 'et_header_layout') {
$layout_id = 'main-header';
}
return $layout_id;
}
add_filter( 'et_builder_layout_id', 'divi_child_set_layout_id', 10, 2);
/**
* THEME BUILDER HEADER FIX
*/
.child.et_fixed_nav.et_show_nav #main-header .et_pb_fullwidth_menu .et_pb_row,
.child.et_non_fixed_nav.et_show_nav #main-header .et_pb_fullwidth_menu .et_pb_row {
margin-top: 0;
margin-bottom: 0;
}
@media screen and (max-width: 980px) {
.child.et_fixed_nav #main-header {
position: fixed; /* Delete this if you don't want a fixed menu on mobile devices! */
}
}
.child .et_pb_fullwidth_menu .et_pb_menu__search {
padding: 0 2rem;
background-color: #fff;
}
/* Fix the upper margin in the Template Builder */
.child header#main-header.et-fb-root-ancestor {
top: 0 !important;
}
/* Fix the padding at the bottom in the Template Builder */
.child header#main-header #et_pb_root {
padding-bottom: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment