Home / Add SEO-friendly Breadcrumbs
Duplicate Snippet

Embed Snippet on Your Site

Add SEO-friendly Breadcrumbs

Automatically add SEO-friendly Breadcrumbs before posts or use as a shortcode for more control.

400+
Code Preview
php
<?php
// You can also use this snippet as a shortcode for more control.
global $post;
if ( ! is_home() ) {
	echo '<div class="breadcrumbs">';
	echo '<a href="' . esc_url( site_url() ) . '">Home</a> / ';
	if ( is_category() || is_single() ) {
		the_category( ' / ' );
		if ( is_single() ) {
			echo ' / ';
			the_title();
		}
	} elseif ( is_page() ) {
		if ( $post->post_parent ) {
			$anc        = get_post_ancestors( $post->ID );
			$page_title = get_the_title();
			foreach ( $anc as $ancestor ) {
				echo '<a href="' . esc_url( get_permalink( $ancestor ) ) . '" title="' . esc_attr( get_the_title( $ancestor ) ) . '">' . esc_html( get_the_title( $ancestor ) ) . '</a> / ';
			}
			echo esc_html( $page_title );
		} else {
			echo '<strong> ' . esc_html( get_the_title() ) . '</strong>';
		}
	}
	echo '</div>';
}

Comments

Add a Comment