Support » Plugin: Yoast SEO » How to tweak breadcrumbs

  • Resolved webelaine

    (@wpgirl369)


    I have a couple of custom post types in subfolders. When I created them, I used the ‘rewrite’ parameter to put them inside an ‘academics’ directory.

    ‘faculty’ custom post type is set to http://mysite.com/academics/faculty/
    ‘program’ custom post type is set to http://mysite.com/academics/programs/

    When I use Yoast SEO breadcrumbs out of the box, the two CPT archives have breadcrumbs that say “Home > CPT”. How can I change this to include the ‘academics’ directory – so the breadcrumbs will be “Home > Academics > CPT”? This applies to the individual CPTs themselves too – for example http://mysite.com/academics/faculty/individual-faculty/ has a breadcrumb of “Home > Faculty > Individual Faculty” but I would like it to be “Home > Academics > Faculty > Individual Faculty”.

    The prefix setting does not help since it adds a prefix to all breadcrumbs.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support amboutwe

    (@amboutwe)

    You or your developer can use the wp_seo_get_bc_ancestors filter to customize this feature.

    webelaine

    (@wpgirl369)

    Thank you, @amboutwe! I had not seen that filter in the documentation. In case it helps someone in the future, here is what I ended up using, as it allowed me to specify post types by name instead of ID:

    add_filter('wpseo_breadcrumb_links', 'my_custom_breadcrumbs');
    function my_custom_breadcrumbs($links) {
         if(is_singular('faculty')) {
              $addedBreadcrumbs = array(
                   array('text' => 'Academics', 'url' => '/academics/', 'allow_html' => 1),
                   array('text' => 'Faculty', 'url' => '/academics/faculty/', 'allow_html' => 1)
              );
              array_splice($links, 1, 1, $addedBreadcrumbs);
         } elseif(is_singular('program')) {
              $addedBreadcrumbs = array(
                   array('text' => 'Academics', 'url' => '/academics/', 'allow_html' => 1),
                   array('text' => 'Programs', 'url' => '/academics/programs/', 'allow_html' => 1)
              );
              array_splice($links, 1, 1, $addedBreadcrumbs);
         }
         return $links;
    }

    Change your post type in if(is_singular('posttype')), set the text you want in 'text' => 'YourText', and set your url in 'url' => 'yoururl'.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to tweak breadcrumbs’ is closed to new replies.