En esta ocasión os presentamos el código que en muchas ocasiones utilizamos para las migas de pan o breadcrumb en nuestros desarrollos en WordPress.
Existen infinidad de plugins para la creación de breadcrumbs pero al no poder tocar el código de estos plugins y estar sujetos a lo que estos permiten nos es un engorro.
Por ejemplo el plugin de WordPress SEO que es un plugin excepcional contiene la opción de «Enlaces Internos» y en muchas ocasiones lo hemos utilizado.

Pero el problema como hemos comentando es que si quieres modificar opciones que se salgan de lo estándar no puedes ya que lo que no es nada aconsejable es ponerte a modificar el core y si es el del WordPress SEO ya ni hablamos.
A continuación os dejamos las tres funciones que se utilizan para la creación de estos breadcrumb personalizados.
function get_category_parents_link_bread( $id, $link = false, $separator = '»', $nicename = false, $visited = array() ) { $chain = ''; $parent = get_term( $id, 'category' ); if ( is_wp_error( $parent ) ) return $parent; if ( $nicename ) $name = $parent->slug; else $name = $parent->name; if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { $visited[] = $parent->parent; $chain .= get_category_parents_link_bread( $parent->parent, true, $separator, $nicename, $visited ); } $chain .= '<li itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb" class="blog"><a itemprop="url" href="' . esc_url( get_category_link( $parent->term_id ) ) . '" title="' .$parent->name. '"><span itemprop="title">'.$name.'</span></a></li>'.$separator; return $chain; } function get_category_parents_bread( $id, $link = false, $separator = '»', $nicename = false, $visited = array() ) { $chain = ''; $parent = get_term( $id, 'category' ); if ( is_wp_error( $parent ) ) return $parent; if ( $nicename ) $name = $parent->slug; else $name = $parent->name; if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { $visited[] = $parent->parent; $chain .= get_category_parents_link_bread( $parent->parent, true, $separator, $nicename, $visited ); } $chain .= '<li itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb" class="blog"><span itemprop="title">'.$name.'</span></li>'.$separator; return $chain; } function seo_breadcrumb() { $showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show $delimiter = ' '; $home = 'Nombre del sitio'; $showCurrent = 1; $before = '<li>'; $after = '</li></ul>'; global $post; $homeLink = get_bloginfo('url'); if (is_home() || is_front_page()) { if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>'; } else { echo '<div style="margin: 0em 0.5em 0em 0.5em;"><ul class="breadcrumb row">'; //echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' '; echo '<li itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="' . $homeLink . '"><span itemprop="title">' . $home . '</span></a></li>'; if ( is_category() ) { // $thisCat = get_category(get_query_var('cat'), false); // if ($thisCat->parent != 0) echo get_category_parents_bread($thisCat->parent, TRUE, ' ' . $delimiter . ' '); // echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after; $catTitle = single_cat_title( "", false ); $cat = get_cat_ID( $catTitle ); echo get_category_parents_bread( $cat, true, ""); } elseif ( is_search() ) { echo $before . 'Resultados para "' . get_search_query() . '"' . $after; } elseif ( is_day() ) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' '; echo $before . get_the_time('d') . $after; } elseif ( is_month() ) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo $before . get_the_time('F') . $after; } elseif ( is_year() ) { echo $before . get_the_time('Y') . $after; } elseif ( is_single() && !is_attachment() ) { if ( get_post_type() != 'post' ) { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo '<a href="' . $homeLink . '»' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a>'; if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after; } else { $cat = get_the_category(); $cat = $cat[0]; $cats = get_category_parents_link_bread($cat, TRUE, ' ' . $delimiter . ' '); if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats); echo $cats; if ($showCurrent == 1) echo $before . get_the_title() . $after; } } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { $post_type = get_post_type_object(get_post_type()); echo $before . $post_type->labels->singular_name . $after; } elseif ( is_attachment() ) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; echo get_category_parents_link_bread($cat, TRUE, ' ' . $delimiter . ' '); echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>'; if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after; } elseif ( is_page() && !$post->post_parent ) { if ($showCurrent == 1) echo $before . get_the_title() . $after; } elseif ( is_page() && $post->post_parent ) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); for ($i = 0; $i < count($breadcrumbs); $i++) { echo $breadcrumbs[$i]; if ($i != count($breadcrumbs)-1) echo ' ' . $delimiter . ' '; } if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after; } elseif ( is_tag() ) { echo $before . 'Etiqueta "' . single_tag_title('', false) . '"' . $after; } elseif ( is_author() ) { global $author; $userdata = get_userdata($author); echo $before . 'Artículos de ' . $userdata->display_name . $after; } elseif ( is_404() ) { echo $before . 'Error 404' . $after; } if ( get_query_var('paged') ) { if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ('; echo __('Página') . ' ' . get_query_var('paged'); if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')'; } echo '</div>'; } }
El css necesario sencillamente es
.breadcrumb > li + li:before { color: #0182dc !important; content: "»" !important; }
Y para poder mostrar estas migas de pan lo que hemos de hacer es sencillamente
seo_breadcrumb();
Otro truco muy práctico es el siguiente con el que conseguimos dado un identificador_de_pagina poder asignar los breadcrumb de deseemos y la ventaja que tendremos con estos es que siendo una página y no un artículo en los rich snippet de la url podremos ver los breadcrumb
<? if (is_page(identificador_de_pagina)) { ?> <div style="padding-bottom:2.2em !important;"> <div class="breadcrumbs"> <span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" title="Seo Tecnico." href="https://seotecnico.es/blog" class="taxonomy category">Seo Tecnico</a></span> > <span typeof="v:Breadcrumb"><a rel="v:url" property="v:title" title="Posicionamiento Web" href="https://seotecnico.es/posicionamiento-web" class="taxonomy category">Posicionamiento Web</a></span> > <span itemprop="title">Posicionamiento Web Seo Girona</span> </div> </div> <? } ?>
obteniendo este resultado de migas de pan en los resultados de búsqueda de google!!!
Si quieres que nuestro equipo te ayude en la implementación dels Breadcrumb o migas de pan de tu site no dudes en ponerte en contacto con nosotros y te realizaremos un presupuesto personalizado