2

I'm adding schema.org markups to my theme's header, but the theme I'm using is calling the_custom_logo();, and by default it uses 'logo' as itemprop.

Is there anyway to change this to image in the functions.php file?

Thanks.

This is the current calling function from the functions.php file.

add_theme_support('custom-logo');
  • Hi, welcome to WPSE. Please find and post that function from your theme's functions.php file. Then i can write a function for you to use in a child theme. – Jack Johansson Jun 7 '17 at 10:06
  • Thanks! I've updated my answer. So, I guess it's just using WordPress's defaults on the function. Please could you let me know how I could change the default 'itemprop="logo"' to 'itemprop="image"'. Thanks. – Jake Jun 7 '17 at 10:06
  • That really doesn't matter. All you need to do is create a code from the_custom_logo() that alters the itemprop from logo to image. It doesn't matter what HTML it's outputting. And from my initial question, you can clearly see that the HTML goes something like, ITEMPROP LOGO! – Jake Jun 7 '17 at 10:14
  • I updated the answer for you. – Jack Johansson Jun 7 '17 at 11:01
1

I assume you have problem with google validator about itemprop="logo". You can hook into the get_custom_header filter and alter the HTML structure:

add_filter( 'get_custom_logo', 'my_custom_logo' );
// Filter the output of logo to fix Googles Error about itemprop logo
function my_custom_logo() {
    $custom_logo_id = get_theme_mod( 'custom_logo' );
    $html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
            esc_url( home_url( '/' ) ),
            wp_get_attachment_image( $custom_logo_id, 'full', false, array(
                'class'    => 'custom-logo',
            ) )
        );
    return $html;   
}

Add the above code to your theme's functions.php or follow the steps here to create a child theme and use this code in it's functions.php file.

Edit

Based on @birgire's comment, i wrote another function to filter the wp_get_attachment_image():

add_filter('wp_get_attachment_image', function ($attachment_id, $size , $icon , $attr) {
        // If the class is 'custom-logo', then change the itemprop to image
        if ($attr['class'] =='custom-logo') {
            $attr['itemprop'] = 'image';
        }
        return $attr;
},10,3);
  • Thanks for commenting, but this doesn't change it. – Jake Jun 7 '17 at 10:33
  • @Jake You should be able to resolve the error by removing the itemprop from the function. – Jack Johansson Jun 7 '17 at 10:34
  • You could also filter the attributes with the wp_get_attachment_image filer and change the itemprop attribute to image, if it's logo and the class is custom-logo. That way we avoid calling wp_get_attachment_image() twice.. – birgire Jun 7 '17 at 10:37
  • 1
    I wouldn't call that a weakness, I would say incremental changes are usually better and show that you care to learn and improve. I've e.g. never heard of a painter that doesn't incrementally improve her painting in many small steps ;-) – birgire Jun 7 '17 at 11:23
  • 1
    @birgire Thank you. I like how you determined the painter's gender already ;) (sorry i know i shouldn't comment irrelevant notes, but couldn't resist anymore after struggling for 20 minutes.) – Jack Johansson Jun 7 '17 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.