If you have access to your functions.php file, adding this snippet will give you a new shortcode [print_my_breadcrumb]
.
Using this with the shortcode block will print a bradcrumb trail.
function print_my_breadcrumb_shortcode() {
// Get the global post variable
global $post;
// Get the home URL for the "Home" link in the breadcrumb
$home = get_bloginfo('url');
// Initialize the output variable with the "Home" link
$output = '<a href="' . $home . '">Home</a>';
// Check the current post type and add the appropriate links to the breadcrumb
if (is_page() || is_single()) {
// Add a link to the parent page
$output .= ' / <a href="' . get_permalink($post->post_parent) . '">' . get_the_title($post->post_parent) . '</a>';
// Add the current page title
$output .= ' / ' . get_the_title();
} elseif (is_category() || is_tax()) {
// Add the current category or taxonomy title
$output .= ' / ' . single_term_title('', false);
} elseif (is_tag()) {
// Add the current tag title
$output .= ' / Tag: ' . single_tag_title('', false);
} elseif (is_year()) {
// Add the current year
$output .= ' / ' . get_the_time('Y');
} elseif (is_month()) {
// Add the current month and year
$output .= ' / ' . get_the_time('F Y');
} elseif (is_day()) {
// Add the current day, month, and year
$output .= ' / ' . get_the_time('F j, Y');
} elseif (is_author()) {
// Add the current author name
$output .= ' / Author: ' . get_the_author();
} elseif (is_search()) {
// Add the current search query
$output .= ' / Search Results for: ' . get_search_query();
} elseif (is_404()) {
// Add a "404 - Page Not Found" message
$output .= ' / 404 - Page Not Found';
}
// Return the breadcrumb trail
return $output;
}
// Register the shortcode
add_shortcode('print_my_breadcrumb', 'print_my_breadcrumb_shortcode');