Yoast\WP\SEO\Presenters
Breadcrumbs_Presenter::crumb_to_link()
Create a breadcrumb element string.
Метод класса: Breadcrumbs_Presenter{}
Хуки из метода
Возвращает
Строку
. The breadcrumb link.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->crumb_to_link( $breadcrumb, $index, $total );
- $breadcrumb(массив) (обязательный)
- Link info array containing the keys: 'text' => (string) link text. 'url' => (string) link url. (optional) 'title' => (string) link title attribute text.
- $index(int) (обязательный)
- Index for the current breadcrumb.
- $total(int) (обязательный)
- The total number of breadcrumbs.
Код Breadcrumbs_Presenter::crumb_to_link() Breadcrumbs Presenter::crumb to link Yoast 24.7
protected function crumb_to_link( $breadcrumb, $index, $total ) { $link = ''; if ( ! isset( $breadcrumb['text'] ) || ! \is_string( $breadcrumb['text'] ) || empty( $breadcrumb['text'] ) ) { return $link; } $text = \trim( $breadcrumb['text'] ); if ( $index < ( $total - 1 ) && isset( $breadcrumb['url'] ) && \is_string( $breadcrumb['url'] ) && ! empty( $breadcrumb['url'] ) ) { // If it's not the last element and we have a url. $link .= '<' . $this->get_element() . '>'; $title_attr = isset( $breadcrumb['title'] ) ? ' title="' . \esc_attr( $breadcrumb['title'] ) . '"' : ''; $link .= '<a'; if ( $this->should_link_target_blank() ) { $link .= ' target="_blank"'; } $link .= ' href="' . \esc_url( $breadcrumb['url'] ) . '"' . $title_attr . '>' . $text . '</a>'; $link .= '</' . $this->get_element() . '>'; } elseif ( $index === ( $total - 1 ) ) { // If it's the last element. if ( $this->helpers->options->get( 'breadcrumbs-boldlast' ) === true ) { $text = '<strong>' . $text . '</strong>'; } $link .= '<' . $this->get_element() . ' class="breadcrumb_last" aria-current="page">' . $text . '</' . $this->get_element() . '>'; } else { // It's not the last element and has no url. $link .= '<' . $this->get_element() . '>' . $text . '</' . $this->get_element() . '>'; } /** * Filter: 'wpseo_breadcrumb_single_link' - Allow changing of each link being put out by the Yoast SEO breadcrumbs class. * * @param string $link_output The output string. * @param array $link The breadcrumb link array. */ return \apply_filters( 'wpseo_breadcrumb_single_link', $link, $breadcrumb ); }