Skip to content

Instantly share code, notes, and snippets.

@mirkoschubert
Created December 12, 2019 13:38
Show Gist options
  • Save mirkoschubert/b22852daaa2ba185d78e53dec80b1746 to your computer and use it in GitHub Desktop.
Save mirkoschubert/b22852daaa2ba185d78e53dec80b1746 to your computer and use it in GitHub Desktop.
Divi 4 Theme Builder Hack for Fixed Navigation Bars (Pt. I)
/**
* 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment