bcn_breadcrumb_title
is the correct filter to use. However, you filter function has some problems with it that are worth discussing.
First, it should just have one return, return $title;
. Since PHP executes in order, the behavior will be the same as what you currently have (it will return right away so the second 2 returns never get executed). For WordPress filters with multiple parameters, only the first is the item to be filtered (and the one you need to return), the others provide context for the filter.
I don’t think the conditions within your if
statement are going to yield what you want. It would be better to check the $type
array for the post type you care about, and then make your call to get_field
. In fact, I would not call get_the_ID()
either. If you want this to only apply when the breadcrumb is for the current item (not sure if that is the intent), you can check the $type
array for 'current_item'
being a member. This really is only necessary if the post type is hierarchical as for non-hierarchical post types aren’t going to have children (so a breadcrumb for said posts will always be the current item).
It appears get_field
is not a WordPress function, the best practice is to check for its existence before calling (to prevent PHP errors if the plugin providing that function isn’t present for some reason).
With these changes, you code would look more like the following:
add_filter('bcn_breadcrumb_title', 'my_breadcrumb_title', 3, 10);
function my_breadcrumb_title($title, $type, $id)
{
if(in_array('your_cpt', $type) && function_exists('get_field')) {
$title = get_field('your_meta_tax', $id);
}
return $title;
}