Avada theme breadcrumb trail fix: categories in correct order

Avada theme breadcrumb trail fix: categories in correct order

It’s no secret I use Avada theme on my site. Recently upgraded it to version 3.8.3 and was really happy that breadcrumb trail started showing category hierachy instead of just last leaf. However, when I yesterday posted about adding more instruments to ZynAddSubFX synthesizer, I noticed that breadcrumb on top of it was kind of weird:

Which is messed. Or to be more precise, bolded path is reversed. Basically only “Home” and direct post category (“4th level”) is correct. Let’s trace issue by inspecting breadcrumbs file located at:

wp-content/themes/Avada/framework/class-breadcrumbs.php

Avada retrieves hierarchy trail in two places – functions get_post_terms and get_taxonomies call WordPress function get_ancestors. Thing is that it returns an array of ancestors from lowest to highest in the hierarchy, which in our case it is:

Array (
[0] => 23
[1] => 22
[2] => 21
[3] => 20
)

On my development environment these are:

23 – 3rd level

22 – 2nd level

21 – 1st level

20 – Root level

If printed out, this array would output reversed breadcrumb trail. That’s why we need to reverse arrays by adding following lines (highlighted) to the code in class-breadcrumbs.php:

In function get_post_terms (starts with line 371):

// If the term has a parent we need its ancestors for a full tree
if ( $term_parent ) {
// Get space separated string of term tree in slugs
$term_tree = get_ancestors( $terms[0]->term_id, $taxonomy );
$term_tree = array_reverse($term_tree);
$term_tree[] = get_term( $terms[0]->term_id, $taxonomy );
// Loop through the term tree
foreach ( $term_tree as $term_id ) {
// Get the term object by its slug
$term_object = get_term( $term_id, $taxonomy );
// Add it to the term breadcrumb markup string
$terms_markup .= $this->get_single_breadcrumb_markup( $term_object->name, get_term_link( $term_object ) );
}
// We have a single term, so put it out
} else {
$terms_markup = $this->get_single_breadcrumb_markup( $terms[0]->name, get_term_link( $terms[0] ) );
}