• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Yoast SEO a2z

Yoast SEO a2z

WordPress SEO a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Breadcrumb::generate() – Returns Schema breadcrumb data to allow recognition of page’s position in the site hierarchy.

You appear to be a bot. Output may be restricted

Description

Returns Schema breadcrumb data to allow recognition of page's position in the site hierarchy.

Usage

$bool|array = Breadcrumb::generate();

Parameters

Returns

bool|array Array on success, false on failure.

Source

File name: wordpress-seo/src/generators/schema/breadcrumb.php
Lines:

1 to 43 of 43
  public function generate() {
    $breadcrumbs   = $this->context->presentation->breadcrumbs;
    $list_elements = [];

    // In case of pagination, replace the last breadcrumb, because it only contains "Page [number]" and has no URL.
    if ( $this->helpers->current_page->is_paged() || ( $this->context->indexable->number_of_pages > 1 ) ) {
      \array_pop( $breadcrumbs );

      $breadcrumbs[] = [
        'url'  => $this->context->canonical,
        'text' => $this->context->title,
      ];
    }

    // Only output breadcrumbs that are not hidden.
    $breadcrumbs = \array_filter( $breadcrumbs, [ $this, 'not_hidden' ] );

    \reset( $breadcrumbs );

    /*
		 * Check whether at least one of the breadcrumbs is broken.
		 * If so, do not output anything.
		 */
    foreach ( $breadcrumbs as $breadcrumb ) {
      if ( $this->is_broken( $breadcrumb ) ) {
        return false;
      }
    }
    // Create the last breadcrumb.
    $last_breadcrumb = \array_pop( $breadcrumbs );
    $breadcrumbs[]   = $this->format_last_breadcrumb( $last_breadcrumb );

    // Create intermediate breadcrumbs.
    foreach ( $breadcrumbs as $index => $breadcrumb ) {
      $list_elements[] = $this->create_breadcrumb( $index, $breadcrumb );
    }

    return [
      '@type'           => 'BreadcrumbList',
      '@id'             => $this->context->canonical . Schema_IDs::BREADCRUMB_HASH,
      'itemListElement' => $list_elements,
    ];
  }
 

 View on GitHub View on Trac

Published: 2nd May 2020 | Last updated: 2nd September 2020

Primary Sidebar

Information

Function name: Breadcrumb::generate
Class ref: Breadcrumb
Plugin ref: Yoast SEO
Version: 15.4
Sourcefile: src/generators/schema/breadcrumb.php
File ref: src/generators/schema/breadcrumb.php
Deprecated?: No
API Letters: B,G

Footer

Yoast SEO a2z
Yoast SEO a2z
WordPress SEO a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wordpress-seo.wp-a2z.org
© Copyright Yoast SEO a2z 2017-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites