Home Notes Web development Yoast Breadcrumbs: Displaying slugs instead of titles

Yoast Breadcrumbs: Displaying slugs instead of titles E-mail
Sunday, 14 March 2010 11:24

I was asked recently how I modified the Yoast Breadcrumbs WordPress plugin to display page slugs instead of page titles.  I won't explain what I did here but only show what modifications I made to the breadcrumbs.php file.  I was working with v. 0.8.4 of the plugin.  Before making any modifications to newer versions, make sure the code looks similar to the original I've pasted here.

 

 

Original:

  // If this is a top level Page, it's simple to output the breadcrumb
  if ( 0 == $post->post_parent ) {
  
 
 
 
 
  $output = $homelink." ".$opt['sep']." ".bold_or_not(get_the_title());
  } else {
   if (isset($post->ancestors)) {

 

Modified code:

// If this is a top level Page, it's simple to output the breadcrumb
  if ( 0 == $post->post_parent ) {
   $temp = get_permalink();
   $temp = explode("/",$temp);
   $temp = array_reverse($temp);
   $temp = $temp[0];
 
   $output = $homelink." ".$opt['sep']." ".bold_or_not($temp);
  } else {
   if (isset($post->ancestors)) {

 

 

Original:

$links = array();   
   foreach ( $ancestors as $ancestor ) {
    $tmp  = array();
    $tmp['title']  = strip_tags( get_the_title( $ancestor ) );
    $tmp['url']  = get_permalink($ancestor);
    $tmp['cur'] = false;
    if ($ancestor == $post->ID) {
     $tmp['cur'] = true;
    }
    $links[] = $tmp;
   }
 
   
 
 
   $output = $homelink;
   foreach ( $links as $link ) {

 

Modified:

$links = array();   
   foreach ( $ancestors as $ancestor ) {
    $tmp  = array();
    $tmp['title']  = strip_tags( get_the_title( $ancestor ) );
    $tmp['url']  = get_permalink($ancestor);
    $temp = explode("/",$tmp['url']);
    $temp = array_reverse($temp);
    $tmp['title'] = $temp[0];
    $tmp['cur'] = false;
    if ($ancestor == $post->ID) {
     $tmp['cur'] = true;
    }
    $links[] = $tmp;
   }
 
   $output = $homelink;
   foreach ( $links as $link ) {