megclaypool of Rootid
6/7/2018 - 12:16 AM

How to enable and use Yoast Breadcrumbs on a WordPress site with Timber/twig

How to enable and use Yoast Breadcrumbs on a WordPress site with Timber/twig

  1. Download and install the Yoast SEO plugin

  2. Add the Yoast Breadcrumb function to timber context

    For Bloom Box, the timber context gets declared in timber.php, inside the add_to_context function

    // Add Yoast Breadcrumbs to the context
      if ( function_exists( 'yoast_breadcrumb' ) ) {
          $context['breadcrumbs'] = yoast_breadcrumb('<nav id="breadcrumbs" class="main-breadcrumbs">','</nav>', false );
      }
    
  3. Add the code to call the breadcrumb function to a template

    For Bloom Box, I added it to system/base.twig, inside a block so we can disable it on any templates we don't want to have breadcrumbs

    {% block breadcrumbs %}
              {% if breadcrumbs %}
                  {{ breadcrumbs }}
              {% endif %} 
          {% endblock %}
    
  4. In the admin sidebar, under SEO/Search Appearance, enable Breadcrumbs