toddius81
Forum Replies Created
-
Forum: Plugins
In reply to: [Breadcrumb NavXT] replace page title with permalink on breadcrumbsHello John,
I am experiencing the same issue. And I am sure others do as well. I am not good with coding and finding a solution to that problem is simply and nightmare. Currently I am settling with the title in the breadcrumbs, but it sure would be great if there was an option to serve the slug, stripped from dashes and capitalised instead. The option with %link% is useless in my case, as it displays the entire url.THANK YOU FOR YOUR QUICK REPLY, BUT PHP IS NOT MY STRENGHT AND I HAVE NO IDEA HOW TO DO IT.
THAT LINE THAT I ADDED
” $link[‘slug’] = get_post_field( ‘post_name’, get_post() ); ”
WAS A PURE MIRACLE THAT I FOUND IT AND IT WORKED.
I HAVE INCLUDED THE SNIPPET WHERE THE MAGIC HAPPENS. IF YOU CAN PLEASE TELL ME WHERE AND WHAT TO INCLUDE, I WOULD BE VERY GREATFUL. THANK YOU/** * Retrieve link url and text based on post id * * @param int $id Post ID. * * @return array Array of link text and url */ private function get_link_info_for_id( $id ) { $link = array(); $link['slug'] = get_post_field( 'post_name', get_post() ); $link['url'] = get_permalink( $id ); $link['text'] = WPSEO_Meta::get_value( 'bctitle', $id ); if ( $link['text'] === '' ) { $link['text'] = strip_tags( get_the_title( $id ) ); } /** * Filter: 'wp_seo_get_bc_title' - Allow developer to filter the Yoast SEO Breadcrumb title. * * @api string $link_text The Breadcrumb title text * * @param int $link_id The post ID */ $link['text'] = apply_filters( 'wp_seo_get_bc_title', $link['text'], $id ); return $link; } /** * Retrieve link url and text based on term object * * @param object $term Term object. * * @return array Array of link text and url */ private function get_link_info_for_term( $term ) { $link = array(); $bctitle = WPSEO_Taxonomy_Meta::get_term_meta( $term, $term->taxonomy, 'bctitle' ); if ( ! is_string( $bctitle ) || $bctitle === '' ) { $bctitle = $term->name; } $link['slug'] = get_post_field( 'post_name', get_post() ); $link['url'] = get_term_link( $term ); $link['text'] = $bctitle; return $link; } /** * Retrieve link url and text based on post type * * @param string $pt Post type. * * @return array Array of link text and url */ private function get_link_info_for_ptarchive( $pt ) { $link = array(); $archive_title = ''; if ( isset( $this->options[ 'bctitle-ptarchive-' . $pt ] ) && $this->options[ 'bctitle-ptarchive-' . $pt ] !== '' ) { $archive_title = $this->options[ 'bctitle-ptarchive-' . $pt ]; } else { $post_type_obj = get_post_type_object( $pt ); if ( is_object( $post_type_obj ) ) { if ( isset( $post_type_obj->label ) && $post_type_obj->label !== '' ) { $archive_title = $post_type_obj->label; } elseif ( isset( $post_type_obj->labels->menu_name ) && $post_type_obj->labels->menu_name !== '' ) { $archive_title = $post_type_obj->labels->menu_name; } else { $archive_title = $post_type_obj->name; } } } $link['slug'] = get_post_field( 'post_name', get_post() ); $link['url'] = get_post_type_archive_link( $pt ); $link['text'] = $archive_title; return $link; } /** * Create a breadcrumb element string * * @todo The <code>$paged</code> variable only works for archives, not for paged articles, so this does not work * for paged article at this moment. * * @param array $link Link info array containing the keys: * 'text' => (string) link text * 'url' => (string) link url * (optional) 'title' => (string) link title attribute text * (optional) 'allow_html' => (bool) whether to (not) escape html in the link text * This prevents html stripping from the text strings set in the * WPSEO -> Internal Links options page. * @param int $i Index for the current breadcrumb. * * @return string */ private function crumb_to_link( $link, $i ) { $link_output = ''; if ( isset( $link['text'] ) && ( is_string( $link['text'] ) && $link['text'] !== '' ) ) { $link['text'] = trim( $link['text'] ); if ( ! isset( $link['allow_html'] ) || $link['allow_html'] !== true ) { $link['text'] = esc_html( $link['text'] ); } $inner_elm = 'span'; if ( $this->options['breadcrumbs-boldlast'] === true && $i === ( $this->crumb_count - 1 ) ) { $inner_elm = 'strong'; } if ( ( isset( $link['url'] ) && ( is_string( $link['url'] ) && $link['url'] !== '' ) ) && ( $i < ( $this->crumb_count - 1 ) ) ) { if ( $i === 0 ) { $link_output .= '<' . $this->element . ' typeof="v:Breadcrumb">'; } else { $link_output .= '<' . $this->element . ' rel="v:child" typeof="v:Breadcrumb">'; } $title_attr = isset( $link['title'] ) ? ' title="' . esc_attr( $link['title'] ) . '"' : ''; $link_output .= '<a href="' . esc_url( $link['url'] ) . '" rel="v:url">' . $link['text'] . '</a>'; } else { $link_output .= '<' . $inner_elm . ' class="breadcrumb_last">' . $link['slug'] . '</' . $inner_elm . '>'; // This is the last element, now close all previous elements. while ( $i > 0 ) { $link_output .= '</' . $this->element . '>'; $i--; } } }
- This reply was modified 8 years, 3 months ago by Steven Stern (sterndata).
- This reply was modified 8 years, 3 months ago by Steven Stern (sterndata). Reason: put code in backticks