home_url(), 'label' => 'Home', ); } /** Generates the breadcrumb for the blog posts index page. * * This method is responsible for creating a breadcrumb entry * that represents the blog posts index page in the breadcrumb trail. * * @return array An associative array representing the breadcrumb for the blog posts index page. */ private static function getBlogPostsIndexBreadcrumb() { return array( 'label' => get_the_title( get_option( 'page_for_posts' ) ) ); } /** Generates the breadcrumb trail for a single post. * * This method is responsible for creating the breadcrumb navigation * specific to single post views. It typically includes links to the * homepage, category (or categories) the post belongs to, and the * post title itself. * * @return array An array representing the breadcrumb trail, where each * element is a breadcrumb item (e.g., URL and label). */ private static function getSinglePostBreadcrumbs() { $breadcrumbs = array(); $categories = get_the_category(); $breadcrumbs[] = array( 'url' => get_permalink( get_option( 'page_for_posts' ) ), 'label' => get_the_title( get_option( 'page_for_posts' ) ), ); if ( ! empty( $categories ) ) { $cat = $categories[0]; $breadcrumbs[] = array( 'url' => get_category_link( $cat ), 'label' => $cat->name, ); } $breadcrumbs[] = array( 'label' => get_the_title() ); return $breadcrumbs; } /** Generates breadcrumbs for custom post types. * * This method is responsible for creating breadcrumb navigation * specific to custom post types. It retrieves and formats the * breadcrumb trail based on the custom post type's hierarchy * and structure. * * @return array An array representing the breadcrumb trail for the custom post type. */ private static function getCustomPostTypeBreadcrumbs() { $breadcrumbs = array(); $postType = get_post_type_object( get_post_type() ); if ( $postType && ! in_array( get_post_type(), array( 'post', 'page' ), true ) ) { $breadcrumbs[] = array( 'url' => get_post_type_archive_link( $postType->name ), 'label' => $postType->labels->name, ); } $breadcrumbs[] = array( 'label' => get_the_title() ); return $breadcrumbs; } /** Generates breadcrumbs for a static page. * * This method is responsible for creating breadcrumb navigation * for static pages in a WordPress theme. It utilizes the provided * post object to determine the breadcrumb structure. * * @param WP_Post $post The WordPress post object representing the static page. * @return array An array of breadcrumb items, where each item is typically * an associative array containing 'title' and 'url' keys. */ private static function getStaticPageBreadcrumbs( $post ) { $breadcrumbs = array(); if ( $post->post_parent ) { $ancestors = array_reverse( get_post_ancestors( $post->ID ) ); foreach ( $ancestors as $ancestor ) { $breadcrumbs[] = array( 'url' => get_permalink( $ancestor ), 'label' => get_the_title( $ancestor ), ); } } $breadcrumbs[] = array( 'label' => get_the_title() ); return $breadcrumbs; } /** Generates a breadcrumb for taxonomy archive pages. * * This method is responsible for creating breadcrumb navigation * specific to taxonomy archive pages, providing users with a clear * path to navigate back to the taxonomy or related sections. * * @return array An array representing the breadcrumb trail for the taxonomy archive. */ private static function getTaxonomyArchiveBreadcrumb() { $term = get_queried_object(); return $term && isset( $term->name ) ? array( 'label' => $term->name ) : array(); } /** Generates a breadcrumb for the archive page of a custom post type. * * This method is responsible for creating a breadcrumb link that points * to the archive page of a specific custom post type. It is typically used * in breadcrumb navigation to provide users with a way to navigate back * to the archive page of the post type they are currently viewing. * * @return array An array containing the breadcrumb data for the custom post type archive. */ private static function getPostTypeArchiveBreadcrumb() { $postType = get_post_type_object( get_post_type() ); return $postType ? array( 'label' => $postType->labels->name ) : array(); } /** Generates breadcrumbs for date-based archives. * * This method is responsible for creating breadcrumb navigation * for WordPress date archive pages, such as year, month, or day archives. * * @return array An array representing the breadcrumb trail for the date archive. */ private static function getDateArchiveBreadcrumbs() { return array( array( 'url' => get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ), 'label' => get_the_date( 'F Y' ), ), array( 'label' => get_the_date() ), ); } /** Generates a breadcrumb for a monthly archive page. * * This method is responsible for creating a breadcrumb * specific to WordPress monthly archive pages. It typically * includes the year and month as part of the breadcrumb trail. * * @return string The HTML markup for the monthly archive breadcrumb. */ private static function getMonthArchiveBreadcrumb() { return array( 'label' => get_the_date( 'F Y' ) ); } /** Generates a breadcrumb for the year-based archive page. * * This method is responsible for creating a breadcrumb link * specific to the year archive in a WordPress site. It is typically * used to provide navigation for users when they are viewing posts * filtered by a specific year. * * @return string The HTML markup for the year archive breadcrumb. */ private static function getYearArchiveBreadcrumb() { return array( 'label' => get_the_date( 'Y' ) ); } /** Generates the breadcrumb for the author archive page. * * This method is responsible for creating a breadcrumb trail * specific to the author archive, providing navigation context * for pages that display posts by a particular author. * * @return string The HTML markup for the author archive breadcrumb. */ private static function getAuthorArchiveBreadcrumb() { $author = get_queried_object(); return array( 'label' => 'Author: ' . $author->display_name ); } /** Generates the breadcrumb for search results. * * This method is responsible for creating a breadcrumb trail * specific to search result pages. It helps users navigate back * to the search context or other parts of the site. * * @return string The HTML markup for the search breadcrumb. */ private static function getSearchBreadcrumb() { return array( 'label' => 'Search: ' . get_search_query() ); } /** Generates the breadcrumb trail for a 404 error page. * * This method is responsible for creating a breadcrumb structure * specifically for 404 error pages, providing users with a navigational * context when a requested page is not found. * * @return array An array representing the breadcrumb trail for the 404 page. */ private static function get404Breadcrumb() { return array( 'label' => '404 Not Found' ); } /** Renders the breadcrumb navigation. * * This method generates and outputs the breadcrumb trail for the current page. * * @return void */ public static function render() { $items = self::generate(); $metadata = array( '@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => array(), ); ob_start(); ?> array( 'class' => array(), 'href' => array(), 'title' => array(), 'rel' => array(), 'target' => array(), 'aria-label' => array(), 'aria-current' => array(), ), 'nav' => array( 'aria-label' => array(), 'class' => array(), 'vocab' => array(), 'typeof' => array(), ), 'span' => array( 'class' => array(), 'aria-current' => array(), ), 'svg' => array( 'class' => array(), 'xmlns' => array(), 'viewBox' => array(), 'fill' => array(), 'aria-hidden' => array(), 'aria-label' => array(), ), 'path' => array( 'd' => array(), 'fill-rule' => array(), 'clip-rule' => array(), 'fill' => array(), 'xmlns:xlink' => array(), ), 'script' => array( 'type' => array(), 'src' => array(), ), ) ); } }