Site logo

Archived topic

Displaying The Current Breadcrumbs On Parent Categories Only

4 replies · Started by Jodie on October 24, 2022

Viewing posts 1–5 of 5

Hi folks,

I've got breadcrumbs via a plugin seperate to Generatepress turned on for my site, and I'm using a generatepress element to display them.

It displays how I want to on posts and subcategories because I've got some custom CSS that hides the last breadcrumb.

This is the code I'm using.

li.breadcrumb-item.active
{display: none;}

However I'd like to display the last breadcrumb on Parent Categories. How can I do that please?

Thanks!

Cheers Jodie

Hi Jodie,

Can you create a Hook Element, then add this code:

	<style>
		li.breadcrumb-item.active
{display: block !important;}
</style>

Hook it to wp_head and set the display rule to Post category archives - all archives

Then add this Snippet:

add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
	if(400138 === $element_id && !is_admin()) {
		$category = get_category( get_query_var( 'cat' ) );
		var_dump($category->category_parent);
		if($category->category_parent > 0) {
			return false;
		}
	} 
	return $display;
    
}, 10, 2 );

Replace 400138 with the ID of the Hook Element you just created.

Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

Hi Fernando,

Great, thanks for that.

How would I get all the breadcrumbs to display on a single line?

Thanks!

Cheers Jodie

Hi there,

this CSS that Fernando provided:

li.breadcrumb-item.active{
    display: block !important;
}

Change to:

li.breadcrumb-item.active{
    display: inline-block !important;
}

Hi David,

Great, that worked, thanks so much for your help!

Cheers Jodie

This archived topic is closed to new replies.