The object type of the “brand” field is not valid

#277662
  • Resolved Joyería G&A
    Rank Math free

    I’m using this code to set brand fields dynamically:

    /**
     * Filter to add custom Brand for WooCommerce Products.
     */
    add_filter('rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    		 if (strpos(get_the_title( $post_id ),'Zippo') !== false) {   
                $entity['brand'] = 'Zippo';    
            } elseif (strpos(get_the_title( $post_id ),"Casio") !== false) {      
                $entity['brand'] = 'Casio';     
            } elseif (strpos(get_the_title( $post_id ),"Q&Q") !== false) {      
                $entity['brand'] = 'Q&Q';
    		} elseif (strpos(get_the_title( $post_id ),"Seiko") !== false) {      
                $entity['brand'] = 'Seiko';
    		} elseif (strpos(get_the_title( $post_id ),"Citizen") !== false) {      
                $entity['brand'] = 'Citizen';  
    		} elseif (strpos(get_the_title( $post_id ),"Parker") !== false) {      
                $entity['brand'] = 'Parker';
    		} elseif (strpos(get_the_title( $post_id ),"Blitz") !== false) {      
                $entity['brand'] = 'Blitz';
    		} elseif (strpos(get_the_title( $post_id ),"Connoisseurs") !== false) {      
                $entity['brand'] = 'Connoisseurs';
    		} elseif (strpos(get_the_title( $post_id ),"Li-Li") !== false) {      
                $entity['brand'] = 'Aros Abridores Li-Li';
    		} elseif (strpos(get_the_title( $post_id ),"CH") !== false) {      
                $entity['brand'] = 'CH Aros Abridores';
    		} elseif (strpos(get_the_title( $post_id ),"Spotify") !== false) {      
                $entity['brand'] = 'Spotify';  
            } else { 
                $entity['brand'] = 'Joyeria GyA';
            }
            return $entity;
    		
    	}
    );

    It’s a variation of the code that I found of your forum as a fix for custom brand:

    /**
     * Filter to add custom Brand for WooCommerce Products.
     */
    add_filter('rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    		$entity['brand'] = 'Rank Math';
    		return $entity;
    	}
    );

    But the code is getting and error in Google search console: The object type of the “brand” field is not valid. I search in the code of the page and its setting the brand type as thing and not as a brand.

Viewing 11 replies - 1 through 11 (of 11 total)
  • you can see the code with the problem found by google in the next image:

    https://ibb.co/fqP1ynW

    Nigel
    Rank Math business

    Hello,

    I modified your code snippet to include the brand type. Replace it with the one below and it should work.

    
    add_filter('rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    		$brandname=""; 
            $entity['brand']['@type'] = 'Brand';
            if (strpos(get_the_title( $post_id ),'Zippo') !== false) {   
                $brandname = 'Zippo';    
            } elseif (strpos(get_the_title( $post_id ),"Casio") !== false) {      
                $brandname = "Casio";     
            } elseif (strpos(get_the_title( $post_id ),"Q&Q") !== false) {      
                $brandname = "Q&Q";
    		} elseif (strpos(get_the_title( $post_id ),"Seiko") !== false) {      
                $brandname = "Seiko";
    		} elseif (strpos(get_the_title( $post_id ),"Citizen") !== false) {      
                $brandname = "Citizen";  
    		} elseif (strpos(get_the_title( $post_id ),"Parker") !== false) {      
                $brandname = "Parker";
    		} elseif (strpos(get_the_title( $post_id ),"Blitz") !== false) {      
                $brandname = "Blitz";
    		} elseif (strpos(get_the_title( $post_id ),"Connoisseurs") !== false) {      
                $brandname = "Connoisseurs";  
            } else { 
                $brandname = "Rank Math";
            }
            $entity['brand']['name']= $brandname;
            return $entity;
    		
    	}
    );
    

    I hope that helps.

    The code is not working. The brand info is not added in any product.

    Hello,

    Can you please clear your website cache and try again?

    If the issue persists, we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Ok

    I added the code with a plugin: Code Snippets (You can access it in the left column, the code is called Brand Schema)

    Hello,

    It seems you forgot to include your website admin URL. Can you please provide it so we can further check the issue?

    We are looking forward to helping you with this one. Thank you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Nigel
    Rank Math business

    Hello,

    Thank you for the sensitive data and additional information. We managed to edit the code snippet with the title “Brand Schema”. The brand schema warning is nolonger showing. Screenshot of rich results test:

    Here is the link to the the results for a product I tested on Google Rich Results Test: https://search.google.com/test/rich-results/result?id=h_BZqk2uISd7n85wzi0L_w

    There are still 2 schema warnings for ‘aggregateRating’ and ‘review’ to fix these you will need to get at least one review from your customers.

    I have commented out your original code snippet in case you want to use it to make adjustments on the new one.

    I hope that helps. If you have questions, ask away. We are here to help.

    thank you!

    Anas
    Rank Math business

    Hello,

    Glad that everything is sorted now.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

Viewing 11 replies - 1 through 11 (of 11 total)

The ticket ‘The object type of the “brand” field is not valid’ is closed to new replies.