Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

(Fix) Missing Item List Field

$
0
0

Replies: 0

I ran into an issue on Google Search Console where I was getting the error missing item list field due to one of the names in my itemListElement array being blank. I saw a lot of people looking for a fix to this problem. What I did is targeted the problematic schema and replaced it with what it needed to be to resolve the error. Hope this helps!

$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ($url === 'https://www.example.com/product/example-product/') {
	add_filter( 'wpseo_schema_graph', 'change_breadcrumbs_item_name_error', 10, 2 );

}
function change_breadcrumbs_item_name_error( $data, $context ) {
    foreach ( $data as $key => $value ) {
        if ( $value['@type'] === 'BreadcrumbList' ) {
			$data[$key]['itemListElement'] = '[{\'@type\':\'ListItem\',\'position\':1,\'name\':\'Home\',\'item\':\'https://www.example.com/\'},{\'@type\':\'ListItem\',\'position\':2,\'name\':\'Products\'},{\'@type\':\'ListItem\',\'position\':3,\'name\':\'Product-Example\'}]';
        }
    }
    return $data;
}

Viewing all articles
Browse latest Browse all 59525

Trending Articles