0

I'm looking for a WordPress way to remove current and all grandparents from breadcrumbs. Basically, functionality is identical to history back button, but with page title. Don't want to do this in JS for obvious reasons. Any ideas?

Cheers!

1 Answer 1

0

You can use wp_get_post_parent_id to return just the parent ID of the page in question. Then you can use get_the_title and get_permalink with that parent ID to build a back button to the parent page;

<?php if( $parent = wp_get_post_parent_id( get_the_ID() ) ): ?>
<a href="<?php echo get_permalink($parent); ?>"><?php echo get_the_title($parent); ?></a>
<?php endif; ?>

Something like this should work. Unable to test this but it should be fine.

Alternatively you could get the entire post parent with get_post and bring out the data you need that way but that is probably more CPU intensive for such a simple thing as getting a link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.