wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

Missing breadcrumb text name within the "breadcrumb structured data schema" Bug Fix.

Open mattu08 opened this issue 4 years ago • 22 comments

  • [x] I've read and understood the contribution guidelines.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

Background: This is the same issue that was patched in Ticket: https://github.com/Yoast/wordpress-seo/issues/13616 and https://github.com/Yoast/wordpress-seo/pull/13617

After Yoast has moved to “indexables that were introduced in 14.0.” referred in @Djennez comment here: https://github.com/Yoast/wordpress-seo/issues/15652#issuecomment-659344491 the following patched code has been removed/is missing in 14.0. So currently sites that do not have the correct schema setup will display errors within breadcrumb schema displaying missing schema values this mainly happens on title and URL if they are empty.

How can we reproduce this behavior?

This can be reproduced if there are missing schema values. With no default value displayed.

Technical info

How to Fix:

To fix the problem of missing or empty values within the schema, I have managed to Patch the issue. By adding in the below error checking code, checking if the value is empty. A similar fix that was in: https://github.com/Yoast/wordpress-seo/issues/13616

To fix this issue I have added the below code to: wordpress-seo –> src –> generators –> schema -> breadcrumb.php Line 97: https://github.com/Yoast/wordpress-seo/blob/6211e5781f7b093e5e3b5e7cc8d24f47cb84beae/src/generators/schema/breadcrumb.php#L97

Current plugin code below:

private function create_breadcrumb( $index, $breadcrumb ) {
		return [
			'@type'    => 'ListItem',
			'position' => ( $index + 1 ),
			'item'     => [
				'@type' => 'WebPage',
				'@id'   => $breadcrumb['url'],
				'url'   => $breadcrumb['url'], // For future proofing, we're trying to change the standard for this.
				'name'  => $this->helpers->schema->html->smart_strip_tags( $breadcrumb['text'] ),
			],
		];
	}

Fixed plugin code below:

        private function create_breadcrumb( $index, $breadcrumb ) {
		if ( empty( $breadcrumb['url'] ) ) {
			$breadcrumb['url'] = $this->context->canonical;
		}
		if ( empty( $breadcrumb['text'] ) ) {
			$breadcrumb['text'] = $this->helpers->schema->html->smart_strip_tags( $this->context->title );
		}
		
		return [
			'@type'    => 'ListItem',
			'position' => ( $index + 1 ),
			'item'     => [
				'@type' => 'WebPage',
				'@id'   => $breadcrumb['url'],
				'url'   => $breadcrumb['url'], // For future proofing, we're trying to change the standard for this.
				'name'  => $this->helpers->schema->html->smart_strip_tags( $breadcrumb['text'] ),
			],
		];
	}

Following code fix added to the above:

                if ( empty( $breadcrumb['url'] ) ) {
			$breadcrumb['url'] = $this->context->canonical;
		}
		if ( empty( $breadcrumb['text'] ) ) {
			$breadcrumb['text'] = $this->helpers->schema->html->smart_strip_tags( $this->context->title );
		}

As an example, from the below function "format_last_breadcrumb" within breadcrumb.php at Line 120, the error checking empty code has already been added, So i'm guessing this has been missed in the above function "create_breadcrumb". https://github.com/Yoast/wordpress-seo/blob/6211e5781f7b093e5e3b5e7cc8d24f47cb84beae/src/generators/schema/breadcrumb.php#L120

Used versions

  • WordPress version: 5.4.2
  • Yoast SEO version: 14.7

mattu08 avatar Aug 05 '20 14:08 mattu08