skip to Main Content

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.

2

Answers


  1. This is a partial answer: in the functions.php file of a child theme (not the parent theme) you can remove the post title from the breadcrumb with this:

    function be_remove_title_from_single_crumb( $crumb, $args ) {
      return substr( $crumb, 0, strrpos( $crumb, $args['sep'] ) );
    }
    add_filter( 'genesis_single_crumb', 'be_remove_title_from_single_crumb', 10, 2 );
    

    from http://www.billerickson.net/code/remove-post-title-from-breadcrumb/

    With that, I’m thinking you can remove the default post title and then – in the same function – check for the existence of a different post title from a meta box or a custom field for that post by, I assume, post ID, and if it exists, return it.

    Also see http://rickrduncan.com/wordpress/customize-genesis-breadcrumb for a reference for all the default arguments from the core function:

    public function __construct() {
        //* Default arguments
        $this->args = array(
            'home'                    => __( 'Home', 'genesis' ),
            'sep'                     => __( ' <span aria-label="breadcrumb separator">/</span> ', 'genesis' ),
            'list_sep'                => ', ',
            'prefix'                  => sprintf( '<div %s>', genesis_attr( 'breadcrumb' ) ),
            'suffix'                  => '</div>',
            'heirarchial_attachments' => true,
            'heirarchial_categories'  => true,
            'labels' => array(
                'prefix'    => __( 'You are here: ', 'genesis' ),
                'author'    => __( 'Archives for ', 'genesis' ),
                'category'  => __( 'Archives for ', 'genesis' ),
                'tag'       => __( 'Archives for ', 'genesis' ),
                'date'      => __( 'Archives for ', 'genesis' ),
                'search'    => __( 'Search for ', 'genesis' ),
                'tax'       => __( 'Archives for ', 'genesis' ),
                'post_type' => __( 'Archives for ', 'genesis' ),
                '404'       => __( 'Not found: ', 'genesis' )
            )
        );
    }
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search