<?php
    // Function to display breadcrumb
    function custom_breadcrumb() {
        echo '<div class="breadcrumb">';
        echo '<a href="' . home_url() . '">Home</a>';

        // Check if on a single post or page
        if (is_single() || is_page()) {
            $post_type = get_post_type();
            if ($post_type != 'post') {
                $post_type_object = get_post_type_object($post_type);
                $post_type_archive = get_post_type_archive_link($post_type);
                echo ' / <a href="' . esc_url($post_type_archive) . '">' . esc_html($post_type_object->labels->singular_name) . '</a>';
            }

            $categories = get_the_category();
            if ($categories) {
                $category = $categories[0];
                echo ' / <a href="' . esc_url(get_category_link($category->term_id)) . '">' . esc_html($category->name) . '</a>';
            }

            echo ' / ' . get_the_title();
        } elseif (is_category()) {
            $category = get_queried_object();
            echo ' / ' . esc_html($category->name);
        } elseif (is_tag()) {
            $tag = get_queried_object();
            echo ' / ' . esc_html($tag->name);
        } elseif (is_author()) {
            $author = get_queried_object();
            echo ' / ' . esc_html($author->display_name);
        } elseif (is_search()) {
            echo ' / Search results for "' . esc_html(get_search_query()) . '"';
        } elseif (is_404()) {
            echo ' / 404 Page Not Found';
        }

        echo '</div>';
    }
?>
