Support » Developing with WordPress » Show Slug In Breadcrumbs Instead of TItle

  • My current breadcrumbs are as follows:
    HOME > CATEGORY > TITLE

    The problem is my blog titles are really long and cause the breadcrumbs to run onto multiple lines.

    Is there a way I could substitute the SLUG for the Title?
    IE: Home > Category > red-car

    Then a related question if the first part can be done.
    Is there a way to format so the “-” is removed from the slug in breadcrumb display?

    IE: Home > Category > Red Car

    Here is my current code…

    function get_breadcrumb() {
        echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
        if (is_category() || is_single()) {
            echo "&nbsp;&nbsp;»&nbsp;&nbsp;";
            the_category(' &bull; ');
                if (is_single()) {
                    echo " &nbsp;&nbsp;»&nbsp;&nbsp; ";
                    the_title();
    
                }
        } elseif (is_page()) {
            echo "&nbsp;&nbsp;»&nbsp;&nbsp;";
            echo the_title();
        } elseif (is_search()) {
            echo "&nbsp;&nbsp;»&nbsp;&nbsp;Search Results for... ";
            echo '"<em>';
            echo the_search_query();
            echo '</em>"';
        }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • You could substitute the_title() with the following:

    if( is_single() ) {
    	echo " &nbsp;&nbsp;»&nbsp;&nbsp; ";
    	$slug = get_post_field( 'post_name' );			// Grab the Slug
    	echo ucwords( str_replace( '-', ' ', $slug );	// Remove dashes, capitalize text
    }

    SYNTAX ERROR UNEXPECTED ‘,’ ‘)’ or ‘;’

    Sorry im new to much of this….any help appreciated.

    Whoops, I should have tested it. Try this:

    if( is_single() ) {
    	echo " &nbsp;&nbsp;»&nbsp;&nbsp; ";
    	$slug = get_post_field( 'post_name' );		// Grab the Slug
    	echo ucwords( str_replace( '-', ' ', $slug ) );	// Remove dashes, capitalize text
    }

    That was it Howdy. Big thanks! 🙂

    Makes it much cleaner for long titles on Mobile/Tablet.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.