/**
* Zeevou Custom Breadcrumb Shortcode
*
* Usage:
*
* Parameters:
* – font_family: Font family name (default: ‘Inter, system-ui, -apple-system, sans-serif’)
* – font_size: Font size with unit (default: ’14px’)
* – color: Text color for links (default: ‘#6B7280’)
* – hover_color: Hover color for links (default: ‘#7C3AED’)
* – separator: Separator character (default: ‘»’)
* – separator_color: Color for separator (default: ‘#9CA3AF’)
* – current_color: Color for current page (default: ‘#111827’)
* – show_home: Show home link (default: ‘yes’)
* – home_text: Text for home link (default: ‘Home’)
*/
if (!function_exists(‘zeevou_custom_breadcrumb_shortcode’)) {
function zeevou_custom_breadcrumb_shortcode($atts) {
// Parse shortcode attributes with defaults
$atts = shortcode_atts([
‘font_family’ => ‘Inter, system-ui, -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, sans-serif’,
‘font_size’ => ’14px’,
‘color’ => ‘#6B7280’,
‘hover_color’ => ‘#7C3AED’,
‘separator’ => ‘»’,
‘separator_color’ => ‘#9CA3AF’,
‘current_color’ => ‘#111827’,
‘show_home’ => ‘yes’,
‘home_text’ => ‘Home’,
], $atts, ‘zeevou_breadcrumb’);
// Start output buffering
ob_start();
// Generate unique ID for this breadcrumb instance
$unique_id = ‘zeevou-breadcrumb-‘ . uniqid();
// Build breadcrumb array
$breadcrumbs = [];
// Add home link
if ($atts[‘show_home’] === ‘yes’) {
$breadcrumbs[] = [
‘title’ => $atts[‘home_text’],
‘url’ => home_url(‘/’),
‘current’ => false
];
}
// Get current post/page
global $post;
if (is_singular()) {
$post_type = get_post_type();
$post_type_object = get_post_type_object($post_type);
// Add archive/parent pages based on post type
if ($post_type !== ‘post’ && $post_type !== ‘page’) {
// Check if there’s a rewrite slug
if ($post_type_object && isset($post_type_object->rewrite[‘slug’])) {
$slug = $post_type_object->rewrite[‘slug’];
// Check if a page exists with this slug
$archive_page = get_page_by_path($slug);
if ($archive_page) {
$breadcrumbs[] = [
‘title’ => get_the_title($archive_page->ID),
‘url’ => get_permalink($archive_page->ID),
‘current’ => false
];
} else {
// Use post type label
$breadcrumbs[] = [
‘title’ => $post_type_object->labels->name,
‘url’ => get_post_type_archive_link($post_type) ?: ‘#’,
‘current’ => false
];
}
}
}
// Add parent pages for hierarchical post types
if (is_post_type_hierarchical($post_type) && $post->post_parent) {
$parent_id = $post->post_parent;
$parents = [];
while ($parent_id) {
$parent = get_post($parent_id);
$parents[] = [
‘title’ => get_the_title($parent->ID),
‘url’ => get_permalink($parent->ID),
‘current’ => false
];
$parent_id = $parent->post_parent;
}
// Reverse to show from top to bottom
$breadcrumbs = array_merge($breadcrumbs, array_reverse($parents));
}
// Add categories for posts
if ($post_type === ‘post’) {
$categories = get_the_category();
if ($categories) {
$category = $categories[0];
$breadcrumbs[] = [
‘title’ => $category->name,
‘url’ => get_category_link($category->term_id),
‘current’ => false
];
}
}
// Add current page/post
$breadcrumbs[] = [
‘title’ => get_the_title(),
‘url’ => get_permalink(),
‘current’ => true
];
} elseif (is_archive()) {
// Handle archive pages
if (is_category() || is_tag() || is_tax()) {
$term = get_queried_object();
$breadcrumbs[] = [
‘title’ => $term->name,
‘url’ => get_term_link($term),
‘current’ => true
];
} elseif (is_post_type_archive()) {
$post_type_object = get_queried_object();
$breadcrumbs[] = [
‘title’ => $post_type_object->labels->name,
‘url’ => get_post_type_archive_link($post_type_object->name),
‘current’ => true
];
}
} elseif (is_search()) {
$breadcrumbs[] = [
‘title’ => ‘Search Results for “‘ . get_search_query() . ‘”‘,
‘url’ => ”,
‘current’ => true
];
} elseif (is_404()) {
$breadcrumbs[] = [
‘title’ => ‘404 – Page Not Found’,
‘url’ => ”,
‘current’ => true
];
}
// Output inline styles
?>