Created
December 12, 2019 11:06
-
-
Save mirkoschubert/80a7bc81e785ff482f57916a61424d74 to your computer and use it in GitHub Desktop.
Divi 4 Theme Builder Hack for Fixed Navigation Bars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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