Checking if site title and tagline settings are checked in Customizer

Question

There is currently the option to display a site’s title and tagline in Customizer.

There doesn’t however appear to be a WordPress function to validate if these are checked or otherwise. The purpose is to display specific headings if these are ticked or unticked.

The code is as follows. It does not return the desired result. If the options (site title and tagline) are unselected, WordPress displays the default output rather than the first condition.

The second condition displays the output as required when the options are selected (i.e. hide site title and tagline).

function custom_logo( $output, $logo_url, $html_attr ) {
        $output = '';
        if (function_exists('get_custom_logo'))
        $custom_logo_id = get_theme_mod( 'custom_logo' );
        $attachment = wp_get_attachment_image_src( $custom_logo_id, 'full', false );
        if ( has_custom_logo() && display_header_text() ) {
            $output = '<div class="site-branding-container"><div class="site-logo"><a href="' . esc_url(home_url('/')) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home"><img width="158" height="150" alt="' . esc_attr(get_bloginfo('name')) . '" src="' . esc_url($attachment[0]) . '" title="' . esc_attr(get_bloginfo('name')) . '" /></a></div></div>';

        } elseif ( has_custom_logo() && !display_header_text() ) {
            $output = '<div class="site-branding-container"><div class="site-logo"><a href="' . esc_url(home_url('/')) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home"><img width="158" height="150" alt="' . esc_attr(get_bloginfo('name')) . '" src="' . esc_url($attachment[0]) . '" title="' . esc_attr(get_bloginfo('name')) . '" /></a></div><div class="site-branding"><h3 class="main-title" itemprop="headline"><a href="' . esc_url(home_url('/')) . '" rel="home">' . esc_attr(get_bloginfo('name')) . '</a></h3></div></div>';

        }

        echo $output;
}

What am I missing?

0
Motivated 2 months 0 Answers 12 views 0

Leave an answer