Logo Alt Atrribute code for functions.php
-
Hello. I am using our company logo in the header. At the time I uploaded the logo image I input the Alt attribute. When I go into the Media library and check the info for the logo image it has the alt attribute field completed. However, I have used several different SEO analysis tools via several different websites and they ALL show my logo as having no ALT attribute.
I tried to solve the problem myself by doing some research on the internet. Per my research I added some code to my child theme’s functions.php file but still I get the same error message
image has no alt attribute: https://collectiblesandmoreinstore.com/wp-content/uploads/2020/02/collectibles-and-more-in-store-abbreviation-camis-slogan-logo.jpg
Please can you help me? The code I currently have added is:
add_theme_support( 'custom-logo' ); function my_custom_logo() { // The logo $custom_logo_id = get_theme_mod( 'custom_logo' ); // If has logo if ( $custom_logo_id ) { // Attr $custom_logo_attr = array( 'class' => 'custom-logo', 'itemprop' => 'logo', ); // Image alt $image_alt = get_post_meta( $custom_logo_id, 'wp_attachment_image_alt', true ); if ( empty( $image_alt ) ) { $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' ); } // Get the image $html = sprintf( '<a href="%1$s" rel="home" title="%2$s">%3$s</a>', esc_url( home_url( '/' ) ), esc_html( get_bloginfo( 'name' ) ), wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ) ); } // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). elseif ( is_customize_preview() ) { $html = sprintf( '<a href="%1$s"><img /></a>', esc_url( home_url( '/' ) ) ); } // Return return $html; } add_filter( 'get_custom_logo', 'my_custom_logo' );
The page I need help with: [log in to see the link]
- The topic ‘Logo Alt Atrribute code for functions.php’ is closed to new replies.