Divi theme – I want to filter out and replace code from a child theme header.php using functions.php and a filter hook. How do I do this?

Question

I’m using the Divi theme and child theme.

I want to remove and replace the below code from the header.php, but I don’t want to use an edited child theme header.php file as this would need to be checked and likely replaced on every theme update.

This is the code from the header.php

<?php ob_start(); ?>
    <header id="main-header" data-height-onload="<?php echo esc_attr( et_get_option( 'menu_height', '66' ) ); ?>">
        <div class="container clearfix et_menu_container">
        <?php
            $logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && ! empty( $user_logo )
                ? $user_logo
                : $template_directory_uri . '/images/logo.png';

            ob_start();
        ?>
            <div class="logo_container">
                <span class="logo_helper"></span>
                <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                    <img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
                </a>
            </div>
        <?php
            $logo_container = ob_get_clean();

            /**
             * Filters the HTML output for the logo container.
             *
             * @since 3.10
             *
             * @param string $logo_container
             */
            echo et_core_intentionally_unescaped( apply_filters( 'et_html_logo_container', $logo_container ), 'html' );
        ?>

Question: Is it possible to do this with a filter hook in functions.php? I understand the hook involved is "et_html_logo_container" – but I don’t know how to write this code.

Any suggestions would be much appreciated.

0
Tom Tolkien 2 months 0 Answers 8 views 0

Leave an answer