Incorrect Structered Data in breadcrumbs
-
There is a small bug in breadcrumbs.php (folder: third-party).
The last item in the navigatiantrail will be written without url
(the Title of the current page shouldn’t be linked)
So Google will say something like “Error, ID needs a correct URL”.Look at row 205:
// Wrap the item with its itemprop. $item = ! empty( $matches ) ? preg_replace( '/(<a.*?)([\'"])>/i', '$1$2 itemprop=$2item$2>', $item ) : sprintf( '<span itemprop="item">%s</span>', $item );
So, I wrote a little more code to solve this:
// Get the post ID, post, current-url // It is probably a bit cumbersome to get the current URL, maybe it's easier $post_id = get_queried_object_id(); $urlid=get_permalink($post_id); // Wrap the item with its itemprop. $item = ! empty( $matches ) ? preg_replace( '/(<a.*?)([\'"])>/i', '$1$2 itemprop=$2item$2>', $item ) : sprintf( '<span itemprop="item" content="%s">%s</span>', $urlid, $item );
It works!
- The topic ‘Incorrect Structered Data in breadcrumbs’ is closed to new replies.