SEO Breadcrumbs Shortcode
Registers a [scseed_breadcrumbs] shortcode that renders a semantic nav breadcrumb trail with home link, optional category, and current page — no plugin required.
PHPby SnipCraft
php
<?php
if ( ! function_exists( 'scseed_breadcrumbs_shortcode_output' ) ) :
function scseed_breadcrumbs_shortcode_output( $atts ) {
$atts = shortcode_atts(
array(
'separator' => ' › ',
'home_text' => 'Home',
),
$atts,
'scseed_breadcrumbs'
);
$sep = '<span class="scseed-bc-sep">' . esc_html( $atts['separator'] ) . '</span>';
$parts = array();
// Home crumb
$parts[] = '<a href="' . esc_url( home_url( '/' ) ) . '">' . esc_html( $atts['home_text'] ) . '</a>';
if ( is_singular() ) {
$cats = get_the_category();
if ( ! empty( $cats ) ) {
$cat = $cats[0];
$parts[] = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '">'
. esc_html( $cat->name ) . '</a>';
}
$parts[] = '<span class="scseed-bc-current">' . esc_html( get_the_title() ) . '</span>';
} elseif ( is_category() ) {
$parts[] = '<span class="scseed-bc-current">' . esc_html( single_cat_title( '', false ) ) . '</span>';
} elseif ( is_tag() ) {
$parts[] = '<span class="scseed-bc-current">' . esc_html( single_tag_title( '', false ) ) . '</span>';
} elseif ( is_tax() ) {
$term = get_queried_object();
$parts[] = '<span class="scseed-bc-current">' . esc_html( $term->name ) . '</span>';
} elseif ( is_search() ) {
$parts[] = '<span class="scseed-bc-current">Search: ' . esc_html( get_search_query() ) . '</span>';
} elseif ( is_404() ) {
$parts[] = '<span class="scseed-bc-current">Page Not Found</span>';
}
return '<nav class="scseed-breadcrumbs" aria-label="Breadcrumb">'
. implode( $sep, $parts )
. '</nav>';
}
add_shortcode( 'scseed_breadcrumbs', 'scseed_breadcrumbs_shortcode_output' );
endif;#breadcrumbs#frontend#navigation#seo#shortcode