Skip to content

Instantly share code, notes, and snippets.

@LeoLopesWeb
Last active June 29, 2022 18:15
Show Gist options
  • Save LeoLopesWeb/14eed38fbf58f3991a3adcaaf8ab2a7b to your computer and use it in GitHub Desktop.
Save LeoLopesWeb/14eed38fbf58f3991a3adcaaf8ab2a7b to your computer and use it in GitHub Desktop.
<?php
function inicio_1() {
echo '<li><a href="'.get_home_url().'">Início</a></li>';
}
function shop_p() {
echo '<li><a href="'.get_permalink( wc_get_page_id( 'shop' ) ).'">Shop</a></li>';
}
function titulo_1() {
echo '<li>'.get_the_title().'</li>';
}
function custom_breadcrumbs() {
ob_start();
global $post;
echo '
<ul class="breadcrumbs">';
if ( !is_front_page() && is_home() ) {
echo inicio_1();
echo '<li>Cases</li>';
}
if ( is_archive() ) {
echo inicio_1();
echo '<li><a href="'.get_post_type_archive_link('post').'">Cases</a></li>';
echo '<li>'.single_term_title( "", false ).'</li>';
}
if ( is_tax() ) {
echo inicio_1();
echo '<li>'.single_term_title( "", false ).'</li>';
}
if (is_singular('post')) {
echo inicio_1();
echo '<li><a href="'.get_post_type_archive_link( 'post' ).'">Cases</a></li>';
echo '<li>'.get_the_title().'</li>';
}
if( is_post_type_archive() ) {
echo inicio_1();
echo '<li>'.str_replace("Archives: ", "", get_the_archive_title()).'</li>';
}
/* if (is_page() && $post->post_parent == 0) {
echo inicio_1();
echo '<li>'.get_the_title().'</li>';
} */
if ( is_page() ) {
/* $parent_id = wp_get_post_parent_id(get_the_ID());
echo inicio_1();
echo '<li><a href="'.get_permalink($parent_id).'">'.get_the_title($parent_id).'</a></li>';
echo '<li>'.get_the_title().'</li>';
*/
$parent = get_post_ancestors(get_the_ID());
$pages = array();
foreach($parent as $p) {
array_push($pages, get_post($p));
}
$hierarchy = get_page_hierarchy($pages);
echo inicio_1();
foreach($hierarchy as $key => $value) {
echo '<li><a href="'.get_permalink($key).'">'.get_the_title($key).'</a></li>';
}
echo '<li>'.get_the_title().'</li>';
}
if ( is_singular('product') ) {
//$terms = get_terms('product_cat');
$terms = get_the_terms( get_the_ID(), 'product_cat' );
/* echo '<pre>';
var_dump($terms);
echo '</pre>'; */
echo shop_p();
echo '<li><a href="'.get_term_link($terms[0]).'">'.$terms[0]->name.'</a></li>';
echo titulo_1();
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo inicio_1().'<li><a href="'.get_post_type_archive_link('post').'">Blog</a></li><li>Search</li>';}
echo '</ul>';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode('breadcrumbs', 'custom_breadcrumbs');
//add_action( 'flatsome_after_header', 'custom_breadcrumbs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment