Check if WP page has parent and link back to it (breadcrumb) | Double Marvellous
Back to Blog
Development Jul 18, 2024 4 min read

Check if WP page has parent and link back to it (breadcrumb)

Check if WP page has parent and link back to it (breadcrumb)

Here’s a quick home-made breadcrumb for WordPress in case you aren’t using the built-in Yoast one or whatever. Add this to your template:

<?php 
$parent = wp_get_post_parent_id(get_the_ID());
if ( $parent ) {
echo '<nav aria-label="breadcrumb"><a href="'.get_permalink( $parent ).'" class="backto"><span>◀</span> Back to '.get_the_title($parent).'</a></nav>';
}
?>

Double Marvellous

AI Chatbot

Double Marvellous.