• Is there a way to dynamically display category with breadcrumbs as a gutenberg block? I could use Pods or ACF if required.

    Say for instance the category is:

    Animals
    – Felines
    — Cats

    I would love to have this displayed in custom header template with a shortcode, like [categories] that I could insert into header text. Then the display would be

    Animals >> Felines >> Cats

    Is this possible?

    • This topic was modified 2 years, 6 months ago by Steven Stern (sterndata).
    • This topic was modified 2 years, 6 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes! There might be a plugin that already provides such a breadcrumb. Try out anything that looks promising from these search results.

    It’s certainly possible to custom develop such a shortcode. If you’re implementing a shortcode, you’d be using the usual shortcode block in a widget area within your header. The category hierarchy you’re after is not appropriate for all pages. For example, it doesn’t make sense for the default front page blog listing because that query does not involve categories at all.

    It does make sense for a single post page, but if multiple category terms are applied, which term should the breadcrumb code use? Simplest solution is to arbitrarily use the first term returned. A hierarchical breadcrumb would also make sense for a category term archive listing. In this case, it’s unambiguous which term to use, but you would determine which term by entirely different means. The point being your shortcode needs to determine what sort of query had been made before it can know how to get the target term, if it should do anything at all.

    Once you have the target term, you can get its ancestor terms with get_ancestors(). A proper breadcrumb trail can then be composed from all the returned term objects. Conveniently, the ancestor function returns terms in hierarchical order.

Viewing 1 replies (of 1 total)
  • The topic ‘How to display categories in breadcrumbs format with gutentberg dynamically?’ is closed to new replies.