|
Hi there, I am trying to get seopress breadcrumbs working on a local site. I have seopress pro and enabling that doesnt show the breadcrumbs. Do i need to overide a template for me to get it working? Plus, how can the breadcrumb be displayed on all pages (minus the home page or other pages i dont want it on?) seems like the breadcrumbs are set to only display on the main blog page and posts... Can you please help me to get this working. Thank you FYI: awseome theme 🙂 |
Replies: 2 comments 6 replies
|
Hello,
No, you can do all with action hooks. See https://bootscore.me/documentation/filter-action-hooks/#actions
Seopress for sure provides something like
WordPress only supports breadcrumbs for posts by default. If you want to add a breadcrumb to pages, you have to write an own for this purpose. Add following snippet to your child's /**
* Custom Breadcrumb for Pages
*/
function custom_page_breadcrumb() {
if (!is_page()) {
return;
}
echo '<nav aria-label="breadcrumb" class="' . apply_filters('bootscore/class/breadcrumb/nav', 'overflow-x-auto text-nowrap mb-4 mt-2 py-2 px-3 bg-body-tertiary rounded') . '">';
echo '<ol class="breadcrumb ' . apply_filters('bootscore/class/breadcrumb/ol', 'flex-nowrap mb-0') . '">';
echo '<li class="breadcrumb-item"><a class="' . apply_filters('bootscore/class/breadcrumb/item/link', '') . '" href="' . home_url() . '">'
. apply_filters('bootscore/icon/home', '<i class="fa-solid fa-house"></i>')
. '<span class="visually-hidden">' . __('Home', 'bootscore') . '</span></a></li>';
// Optional: Include parent pages if nested
if ($post = get_post()) {
$parents = array_reverse(get_post_ancestors($post));
foreach ($parents as $parent_id) {
$parent = get_post($parent_id);
echo '<li class="breadcrumb-item"><a class="' . apply_filters('bootscore/class/breadcrumb/item/link', '') . '" href="' . get_permalink($parent) . '">' . get_the_title($parent) . '</a></li>';
}
}
echo '<li class="breadcrumb-item active" aria-current="page">' . get_the_title() . '</li>';
echo '</ol>';
echo '</nav>';
}
add_action('bootscore_after_primary_open', 'custom_page_breadcrumb');Does this help? |
Thats what I did to add the default bredacrumb into the templates Actually i went down i dfferent route to the other code you provided. Here is what I did (work in progress) i chnaged the breadcrumb.php file to: if ( ! function_exists( 'the_breadcrumb' ) ) :
function the_breadcrumb() {
if ( ! is_home() ) {
echo '<nav aria-label="breadcrumb" class="' . apply_filters( 'bootscore/class/breadcrumb/nav', 'overflow-x-auto text-nowrap mb-4 mt-2 py-2 px-3 bg-body-tertiary rounded' ) . '">';
if ( function_exists( 'seopress_display_breadcrumbs' ) ) {
$raw = seopress_display_breadcrumbs( false );
$raw = preg_replace( '#^<nav[^>]*>|</nav>$#is', '', $raw );
$raw = preg_replace( '#^<ol[^>]*>|</ol>$#is', '', $raw );
if ( preg_match( '#^(.*?)<li#is', $raw, $pmatch ) ) {
$prefix = trim( $pmatch[1] );
if ( $prefix ) {
echo $prefix;
}
}
if ( preg_match_all( '#<li[^>]*>(.*?)</li>#is', $raw, $lmatches ) ) {
$items = $lmatches[1];
} else {
$items = array();
}
echo '<ol class="breadcrumb ' . esc_attr( apply_filters( 'bootscore/class/breadcrumb/ol', 'flex-nowrap mb-0' ) ) . '">';
$count = count( $items );
foreach ( $items as $i => $inner ) {
$inner = trim( $inner );
if ( $i === $count - 1 ) {
echo '<li class="breadcrumb-item active" aria-current="page">' . $inner . '</li>';
} else {
echo '<li class="breadcrumb-item">' . $inner . '</li>';
}
}
echo '</ol>';
} else {
echo '<ol class="breadcrumb ' . esc_attr( apply_filters( 'bootscore/class/breadcrumb/ol', 'container flex-nowrap mb-0' ) ) . '">';
echo '<li class="breadcrumb-item"><a class="' . apply_filters( 'bootscore/class/breadcrumb/item/link', '' ) . '" href="' . esc_url( home_url() ) . '">' . apply_filters( 'bootscore/icon/home', '<i class="fa-solid fa-house"></i>' ) . '<span class="visually-hidden">' . __( 'Home', 'bootscore' ) . '</span></a></li>';
if ( is_category() || is_single() || is_page() ) {
$cat_ids = wp_get_post_categories( get_the_ID() );
foreach ( $cat_ids as $cat_id ) {
$cat = get_category( $cat_id );
echo '<li class="breadcrumb-item"><a class="' . apply_filters( 'bootscore/class/breadcrumb/item/link', '' ) . '" href="' . esc_url( get_term_link( $cat->term_id ) ) . '">' . esc_html( $cat->name ) . '</a></li>';
}
}
if ( is_page() || is_single() ) {
echo '<li class="breadcrumb-item active" aria-current="page">' . esc_html( get_the_title() ) . '</li>';
}
echo '</ol>';
}
echo '</nav>';
}
}
endif;Checks if seopress breadcrumbs is turned on and uses that BUT keeps the styling the same as default breadcrumbs (seopress doesnt come with styling) and if its not turned on then it defaults back to the bootscore breadcrumbs... Working so far but need to iron out a few bugs... The ONLY downside I have seen so far is that i cannot use this breadcrumb.php in my child-heme and have to overwrite the parent file 😯 ill check your code too to see how i can use that if its better (probarbly is...) any other suggestions would be helpful... |
All good, this forum exists to ask questions, get answers and learning. Your questions are legitimate. Let's break that down to clarify how the breadcrumb(s) works and how to add them to the
blankpages.Default breadcrumb
This is the default WordPress breadcrumb and supports only single posts. The function is in https://github.com/bootscore/bootscore/blob/main/inc/breadcrumb.php and called in the
single-*phptemplates:bootscore/single-templates/single-sidebar-left.php
Line 21 in 67285f7
You can edit appearance, means classes and icon by filters https://bootscore.me/documentation/fil…