$home_label !== '' ? $home_label : 'Home', 'url' => citami_schema_home_url())); if (!$post) { return $items; } if ($post->post_type === 'page' && !empty($post->post_parent)) { $chain = array(); $parent = get_post((int) $post->post_parent); $guard = 0; while ($parent && $guard++ < 10) { array_unshift($chain, $parent); $parent = !empty($parent->post_parent) ? get_post((int) $parent->post_parent) : null; } foreach ($chain as $p) { $items[] = array('name' => (string) $p->post_title, 'url' => get_permalink($p)); } } elseif ($post->post_type === 'post' && function_exists('get_the_category')) { $cats = get_the_category($post->ID); if (is_array($cats) && !empty($cats) && isset($cats[0]->name)) { $link = function_exists('get_category_link') ? get_category_link($cats[0]) : ''; $items[] = array('name' => (string) $cats[0]->name, 'url' => is_string($link) ? $link : ''); } } $items[] = array('name' => (string) $post->post_title, 'url' => get_permalink($post)); return $items; } /** HTML for the current request (empty on home). */ function citami_breadcrumb_html($separator = '›') { if (is_front_page() || is_home()) { return ''; } $post = is_singular() ? get_post() : null; if (!$post) { return ''; } $items = citami_breadcrumb_items($post); $last = count($items) - 1; $html = ''; } /** Template tag: */ function citami_breadcrumb($separator = '›') { echo wp_kses(citami_breadcrumb_html($separator), citami_kses_allowed()); } add_shortcode('citami_breadcrumb', function ($atts) { $atts = shortcode_atts(array('sep' => '›'), $atts, 'citami_breadcrumb'); return citami_breadcrumb_html((string) $atts['sep']); });