Site logo

Archived topic

How can I hook a breadcrumb shortcode into a custom post template?

5 replies · Started by Lilo on June 26, 2021

Viewing posts 1–6 of 6

Hi,

The breadcrumb shortcode doesn't show up after the entry title when I'm using custom post templates (it works without custom post templates), is this normal?

If yes then it would be useful to have a GP/GB native breadcrumbs block. I know that I can use the NavXT plugin and include a breadcrumbs block on templates, did it before – but it would be great if it would work without an additional plugin just using a seo plugin and GP/GB.

Other themes e.g. Kadence also ship their own breadcrumb block with their theme instead of their blocks plugin, otherwise I'd use that because I'm already using some of their blocks.

Hi there,

If you're using the hook or block element to add your shortcode then there can two main reasons as to why it didn't display:

1. The Display Rules location is not set correctly. Make sure the cpt slug is included in the locations.
2. The CPT does not include the Hook you have set it to.

On #2 - if you need GP Hooks in your CPTs then it is best to build your templates using copies of the Theme templates, then you can keep the hooks you need.

The "custom" in my previous post just refers to the custom post template using a block element content template, I didn't create a CPT because the template should use the default post-type of post.

The hook setting is generate_before_entry_title. The location display rule for the breadcrumb shortcode hook is set to post - all posts.

For the block template I'm using a block element with its type set to content template applied to all posts. The block element template is created like usual with dynamic content and headline blocks fetching the post title.

Is it even possible to use hooks on post templates created with block elements?

Aah ok - Block Element Content Templates overwrite the Theme templates entirely - which removes any hooks. You would have to include the Breadcrumb shortcode within the Block Element itself.

Makes sense, today I learned that I can insert shortcodes with Gutenberg, thanks!

Glad to be of help

This archived topic is closed to new replies.