Breadcrumbs final label appearing out of list?

Hybrid Core (framework) 7 posts 2 voices

  1. I’ve amended a few bits for the breadcrumbs when it appears on a single-cp.php page.

    The issue is the final post name i/e the page we’re on is appearing out of the li list?

    Is basically showing this ignoring the links and semantic bits..

    Post Type Name
    		<li> (Post Type Name should be here) <li>
    function my_breadcrumb_trail_items( $items ) {
    	if ( is_singular( 'work-area' ) ) {
    				$items = array();
    				$items[] = '<a href="' . home_url() . '" title="' .home_url( '/work-sections/interiors/') . '">Work</a>';
    				$items[] = '<a href="">Interiors</a>';
    				$items[] = single_post_title();
    	return $items;
    add_filter( 'breadcrumb_trail_items', 'my_breadcrumb_trail_items' );
  2. You have single_post_title() set to display instead of return. Change that line to:

    $items[] = single_post_title( '', false );
  3. Brillant thanks Justin.

    I dont suppose there is quick explanation what that happens and why your example moves it into the li rather than outside?

  4. My code returns the variable so that it can later be used, which is what we need to happen. In this particular case, it’ll later be formatted and wrapped up in an <li>.

    $items[] = expects a value to be assigned to it. single_post_title( '', false ) says to return the post title, which means that it gets assigned to the $items array. The false part there tells the single_post_title() function to return.

    Your code just directly prints the post title to the screen. Technically speaking, your code is broken. It’s just that PHP doesn’t throw an error and manages to “work,” which kind of makes it hard to track down things like this sometimes. I just happened to know how the single_post_title() function works, so this one was easier to spot than others.

  5. Having this issue again, but this time with..

    Both $items[] = the_archive_title(); and $items[] = the_archive_title( '', false );

    Place the final CPT archive title out of the breadcrumb li’s

    Any ideas?