How can I create a breadcrumb? I have to create a breadcrumb so that, if a page has a menu, the breadcrumb should be the menu with its hierarchy. If the node page doesn't have a menu, the page title should be in the breadcrumb.

I tries the Menu breadcrumb module. Menu pages are coming correctly, but other pages are showing the page title in the breadcrumb.

How can I achieve this?
You can do this by creating custom module and creating yourmodule.services.yml

services:
  yourmodule.breadcrumb:
    class: Drupal\yourmodule\FwsBreadcrumbBuilder
    tags:
      - { name: breadcrumb_builder, priority: 100 }


and creating custom class which should extend BreadcrumbBuilderInterface like this 

class FwsBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  public function applies(RouteMatchInterface $route_match) {
    $route = $route_match-&gt;getCurrentRouteMatch();
    // Add conditionals that return TRUE when the current route should have it's
    // breadcrumb handled here.
    return FALSE;
  }

  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $breadcrumb-&gt;addCacheContexts(['route']);

    // Add logic here that builds up the breadcrumbs based on desired behaviour.
    $links[] = Link::createFromRoute(t('Home One'), '&lt;front&gt;');

    $breadcrumb-&gt;setLinks($links);

    return $breadcrumb;
  }
}


I have also got the above code from http://drupal.stackexchange.com

You can also add new and alter previous breadcrumbs in hook_preprocess_HOOK function like this

function yourmodule_or_yourtheme_preprocess_breadcrumb(&amp;$variables) {
    // Your Logic Here
}