summaryrefslogtreecommitdiff
blob: 0e524f7b5ccdb9d2838e66e175881452ce8dd964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/**
 * Plugin Name: Site Breadcrumbs
 * Plugin URI: http://wordpress.com
 * Description: Quickly add breadcrumbs to the single view of a hierarchical post type
 * Author: Automattic
 * Version: 1.0
 * Author URI: http://wordpress.com
 * License: GPL2 or later
 */

function jetpack_breadcrumbs() {
	if ( ! is_page() || is_front_page() ) {
		return;
	}

	global $post;

	$ancestors = array_reverse( get_post_ancestors( $post->ID ) );

	$before = '<nav class="entry-breadcrumbs">';
	$after = '</nav>';

	$home = '<a href="' . esc_url( home_url( "/" ) ) . '" class="home-link" rel="home">' . __( 'Home', 'jetpack' ) . '</a>';

	$breadcrumb = '';

	if ( $ancestors ) {
		foreach ( $ancestors as $ancestor ) {
			$breadcrumb .= '<a href="' . esc_url( get_permalink( $ancestor ) ) . '">' . esc_html( get_the_title( $ancestor ) ) . '</a>';
		}
	}

	$breadcrumb .= '<span class="current-page">' . esc_html( get_the_title( $post->ID ) ) . '</span>';

	echo $before . $home . $breadcrumb . $after;
}