Search code examples
phpwordpressgenesis

Set a custom breadcrumb in WordPress / Genesis that is different from the post / page title


My company has been developing our own child theme for WordPress / Genesis builds that we use as standard for all of our clients. For SEO we sometimes have longer page titles that don't look good in the breadcrumbs. i.e. "Brick Services In Sometown". It ends up looking like this:

Home / Brick Services In Sometown / Acme Bricks

What we're wanting to do is be able to have a field on the page / post editor that allows us to enter custom text for the breadcrumb, so it would look like:

Home / Services / Acme Bricks

I know how to add the appropriate meta boxes to the backend and add the entered info into the post / page meta, but the only way I see to accomplish using this extra data for the breadcrumbs is by editing the Genesis core theme files, which I don't want to do. I would like to accomplish this within the child theme so updating is not a hassle.

If I were to edit the Genesis core breadcrumb.php file I'd do something like:

$ub_breadcrumb = esc_html( get_post_meta( $post->ID, '_ub_breadcrumb', TRUE ) );
if ( !empty( $ub_breadcrumb )) {

//* Add the custom page title for breadcrumbs if value is set
$crumbs[] = $ub_breadcrumb;
} else {

//* Add the current page title
$crumbs[] = get_the_title( $post->ID );
}

This is from the genesis/lib/classes/breadcrumb.php core file on line 363. I'd do something similar for the ancestors of the current page / post in the section above that as well.

Is there another way to accomplish this without editing the core theme files? We're trying to keep this all in the child theme so it's update proof ( as much as can be anyways ).

Thanks. It's an odd thing to Google for, so I haven't found anything besides the built-in breadcrumb filters in Genesis, but those don't cover the post / page title.


Solution

  • I've not updated it in a while, but you may like to give my plugin a go:

    https://github.com/GaryJones/genesis-single-breadcrumbs

    Screenshot of the fields added with Genesis Single Breadcrumbs plugin