I want to display the full path in my breacrumbs by changing the theme function. Some plugin (like Brands) adds pages but they’re not processed by the breadcrumbs, so if I’m visiting the page mysite.com/brands/brandname In the page I only see Home /
while it should be Home / Brands / Brandname
.
Breadcrumb theme function:
if ( ! function_exists( 'montagne_core_breadcrumbs' ) ) {
/**
* Function that renders breadcrumbs html
*/
function montagne_core_breadcrumbs() {
$page_id = qode_framework_get_page_id();
// Breadcrumbs label
$labels = apply_filters(
'montagne_core_filter_breadcrumbs_label',
array(
'home' => esc_html__( 'Home', 'montagne-core' ),
'tag' => esc_html__( 'Posts tagged "%s"', 'montagne-core' ),
'author' => esc_html__( 'Posted by %s', 'montagne-core' ),
'search' => esc_html__( 'Search results for "%s"', 'montagne-core' ),
'404' => esc_html__( '404 - Page not found', 'montagne-core' ),
'query_paged' => esc_html__( '(Page %s)', 'montagne-core' ),
)
);
// Breadcrumbs variables
$settings = apply_filters(
'montagne_core_filter_breadcrumbs_settings',
array(
'wrap_before' => '<div itemprop="breadcrumb" class="qodef-breadcrumbs">',
'wrap_after' => '</div>',
'home_url' => esc_url( home_url( "https://stackoverflow.com/" ) ),
'link' => '<a itemprop="url" class="qodef-breadcrumbs-link" href="%1$s"><span itemprop="title">' . '%2$s' . '</span></a>',
'current_item' => '<span itemprop="title" class="qodef-breadcrumbs-current">' . '%1$s' . '</span>',
'separator' => '<span class="qodef-breadcrumbs-separator"></span>',
)
);
$wrap_child = '';
if ( is_home() && ! is_front_page() ) {
$wrap = sprintf( $settings['link'], $settings['home_url'], $labels['home'] ) . $settings['separator'] . sprintf( $settings['current_item'], get_the_title( $page_id ) );
} elseif ( is_home() || is_front_page() ) {
$wrap = sprintf( $labels['home'] );
} else {
$wrap = sprintf( $settings['link'], $settings['home_url'], $labels['home'] ) . $settings['separator'];
if ( is_tag() ) {
$wrap_child .= sprintf( $settings['current_item'], sprintf( $labels['tag'], single_tag_title( '', false ) ) );
} elseif ( is_day() ) {
$wrap_child .= sprintf( $settings['link'], get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) ) . $settings['separator'];
$wrap_child .= sprintf( $settings['link'], get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ), get_the_time( 'F' ) ) . $settings['separator'];
$wrap_child .= sprintf( $settings['current_item'], get_the_time( 'd' ) );
} elseif ( is_month() ) {
$wrap_child .= sprintf( $settings['link'], get_year_link( get_the_time( 'Y' ) ), get_the_time( 'Y' ) ) . $settings['separator'];
$wrap_child .= sprintf( $settings['current_item'], get_the_time( 'F' ) );
} elseif ( is_year() ) {
$wrap_child .= sprintf( $settings['current_item'], get_the_time( 'Y' ) );
} elseif ( is_author() ) {
$wrap_child .= sprintf( $settings['current_item'], sprintf( $labels['author'], get_the_author_meta( 'display_name', get_query_var( 'author' ) ) ) );
} elseif ( is_category() ) {
$category = get_category( get_query_var( 'cat' ), false );
if ( isset( $category->parent ) && 0 !== $category->parent ) {
$wrap_child .= get_category_parents( $category->parent, true, $settings['separator'] );
}
$wrap_child .= sprintf( $settings['current_item'], single_cat_title( '', false ) );
} elseif ( is_search() ) {
$wrap_child .= sprintf( $settings['current_item'], sprintf( $labels['search'], get_search_query() ) );
} elseif ( is_404() ) {
$wrap_child .= sprintf( $settings['current_item'], $labels['404'] );
} elseif ( is_single() ) {
if ( is_singular( 'post' ) ) {
$category = get_the_category();
$wrap_child .= get_category_parents( $category[0], true, $settings['separator'] );
}
$wrap_child .= sprintf( $settings['current_item'], get_the_title() );
} elseif ( is_page() ) {
global $post;
if ( $post->post_parent ) {
$parent_ids = array();
$parent_ids[] = $post->post_parent;
foreach ( $parent_ids as $parent_id ) {
$wrap_child .= sprintf( $settings['link'], get_the_permalink( $parent_id ), get_the_title( $parent_id ) ) . $settings['separator'];
}
}
$wrap_child .= sprintf( $settings['current_item'], get_the_title() );
}
if ( get_query_var( 'paged' ) ) {
$wrap_child .= sprintf( $settings['current_item'], sprintf( $labels['query_paged'], get_query_var( 'paged' ) ) );
}
}
// Breadcrumbs html template
$breadcrumbs_html="";
if ( ! empty( $wrap ) ) {
$breadcrumbs_html = $settings['wrap_before'] . $wrap . apply_filters( 'montagne_core_filter_breadcrumbs_content', $wrap_child, $settings ) . $settings['wrap_after'];
}
echo apply_filters( 'montagne_core_filter_breadcrumbs_template', $breadcrumbs_html );
}
}
I tried replacing it with:
function montagne_core_breadcrumbs()
{
$settings = apply_filters(
'montagne_core_filter_breadcrumbs_settings',
array(
'wrap_before' => '<div itemprop="breadcrumb" class="qodef-breadcrumbs">',
'wrap_after' => '</div>',
'home_url' => esc_url(home_url("https://stackoverflow.com/")),
'link' => '<a itemprop="url" class="qodef-breadcrumbs-link" href="%1$s"><span itemprop="title">%2$s</span></a>',
'current_item' => '<span itemprop="title" class="qodef-breadcrumbs-current">%1$s</span>',
'separator' => '<span class="qodef-breadcrumbs-separator"></span>',
)
);
$wrap_child = '';
$breadcrumbs = array();
if (!is_front_page()) {
$breadcrumbs[] = sprintf($settings['link'], $settings['home_url'], $settings['home']);
}
if (is_category() || is_single() || is_page()) {
$categories = get_the_category();
$category_parents = array();
foreach ($categories as $category) {
$category_parents[] = get_category_parents($category->term_id, true, $settings['separator']);
}
$breadcrumbs[] = implode($settings['separator'], $category_parents);
}
if (is_single() || is_page()) {
$breadcrumbs[] = sprintf($settings['current_item'], get_the_title());
}
if (is_search()) {
$breadcrumbs[] = sprintf($settings['current_item'], sprintf($settings['labels']['search'], get_search_query()));
}
if (is_404()) {
$breadcrumbs[] = sprintf($settings['current_item'], $settings['labels']['404']);
}
if (is_home() && !is_front_page()) {
$breadcrumbs[] = sprintf($settings['current_item'], get_the_title());
}
if (is_tag()) {
$breadcrumbs[] = sprintf($settings['current_item'], sprintf($settings['labels']['tag'], single_tag_title('', false)));
}
if (is_author()) {
$breadcrumbs[] = sprintf($settings['current_item'], sprintf($settings['labels']['author'], get_the_author()));
}
if (is_year() || is_month() || is_day()) {
$breadcrumbs[] = sprintf($settings['current_item'], get_the_time('Y'));
}
if (get_query_var('paged')) {
$breadcrumbs[] = sprintf($settings['current_item'], sprintf($settings['labels']['query_paged'], get_query_var('paged')));
}
$breadcrumbs_html = implode($settings['separator'], $breadcrumbs);
if (!empty($breadcrumbs_html)) {
echo $settings['wrap_before'] . $breadcrumbs_html . $settings['wrap_after'];
}
}
This way the breadcrumb it’s all empty. Is there a way to slice the url and print it as breadcrumb path when the page i