Breadcrumbs in Ethos

Hi,
Ive tried many of the codes mentioned in the forum to add breadcrumbs to Ethos but nothing works.
In the past I asked for breakcrumbs going back to the blog page from all single posts and this code below works, but I want all the single archives posts to go back to the main archive pages. as well as single posts going back to the blog.

Can I edit this code to function that way:
TIA!

add_action( 'x_before_view_global__index', 'print_breadcrumb_for_category' );
add_action( 'x_before_view_integrity_content', 'print_breadcrumb_for_post' );

function print_breadcrumb_for_category () {
if ( is_category() ) custom_breadcrumbs();
}
function print_breadcrumb_for_post () {
if ( is_singular( 'post' ) )  custom_breadcrumbs();
}
function custom_breadcrumbs() { ?>
		<div class="custom-breadcrumb">
			<a href="<?php echo get_permalink( get_option('page_for_posts') ); ?>">&#60; Return to Blog</a>
		</div>
		<?php
}

Hi @fatcatgraphics,

Thanks for reaching out.

Yes, you could do that by just replacing this <a href="<?php echo get_permalink( get_option('page_for_posts') ); ?>">&#60; Return to Blog</a> with your own custom code. An example is from this https://wordpress.stackexchange.com/questions/38237/how-to-get-the-category-of-the-post-and-link-it-to-the-archive-of-the-category

<?php $category = get_the_category();  echo '<a href="'.get_category_link($category[0]->cat_ID).'">Return to  ' . $category[0]->cat_name . '</a>'; ?>

But that would only add a return link for the post which isn’t really related to breadcrumb.

Thanks!

Oh ok, well than how can i get true breadcrumbs?

Hi @fatcatgraphics,

It’s quite broad and would require customization which we can’t really provide in the forum. It’s not simple and depends on your requirement and to where it will be implemented. Another approach is just modifying the existing breadcrumb like from here https://theme.co/apex/forum/t/change-nam-of-blog/53565/13

add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);

function post_parent_trail ($crumbs, $args) {
  if ( is_singular('post') ) {

    $category = get_the_category( get_the_ID() );
    if ( count( $category ) > 0 ) {
    $crumbs[1]['label'] = $category[0]->name;
    $crumbs[1]['url'] = get_category_link( $category[0]->term_id );
    
   unset($crumbs[2]); //to make sure category won't duplicate

    }
  }
  return $crumbs;
}

Then you should see the changes in your existing breadcrumb once it’s active (Theme Options > Header > MISCELLANEOUS > BREADCRUMBS)

Thanks!

Ok, i see… So ill go back to your other idea of doing the fake bread crumbs with the code pasted below. The only problem is that its supposed to display on category archive single posts. But its displaying on category archives.
So its saying ‘back to category archive’ when its already on cat. archive.
How can i get it to display on single posts?

add_action( 'x_before_view_global__index', 'print_breadcrumb_for_category' );
add_action( 'x_before_view_integrity_content', 'print_breadcrumb_for_post' );

function print_breadcrumb_for_category () {
if ( is_category() ) custom_breadcrumbs();
}
function print_breadcrumb_for_post () {
if ( is_singular( 'post' ) )  custom_breadcrumbs();
}
function custom_breadcrumbs() { ?>
		<div class="custom-breadcrumb">
			<?php $category = get_the_category();  echo '<a href="'.get_category_link($category[0]->cat_ID).'">Return to  ' . $category[0]->cat_name . '</a>'; ?>
		</div>
		<?php
}

Hello @fatcatgraphics,

Your code displays the same custom breadcrumbs. You must have other function to display when it is a category archive and have something different when it is a single post.

And by the way, your code will create an issue when viewing a single post. Please keep in mind that one single post can have several categories. You will have problems with your code.

I would recommend that you just create a go back button instead. Please refer to his thread:

Hope this helps.

Ok, but in order for me to add a back button like that I need to copy the single post page, and recreate it in a child theme and then add this button right? What page is it in Ethos?

Hi @fatcatgraphics,

You may copy the file wp-content\themes\x\framework\views\ethos\wp-single.php to your child theme
wp-content\themes\x-child\framework\views\ethos\wp-single.php then add your code on that file.

For more information kindly review the link below

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.