[Resolved] Displaying The Current Breadcrumbs On Parent Categories Only

Home Forums Support [Resolved] Displaying The Current Breadcrumbs On Parent Categories Only

Home Forums Support Displaying The Current Breadcrumbs On Parent Categories Only

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2383733
    Jodie

    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

    #2383803
    Fernando
    Customer Support

    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

    #2383928
    Jodie

    Hi Fernando,

    Great, thanks for that.

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

    Thanks!

    Cheers Jodie

    #2383990
    David
    Staff
    Customer Support

    Hi there,

    this CSS that Fernando provided:

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

    Change to:

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

    Hi David,

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

    Cheers Jodie

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.