Breadcrumbs shortcode?

Hello there,

We've designed a few pages where we used the Breadcrumbs element.

We'd like to include it in our custom product category archives.

Is there a way to return this element via a shortcode?

If not, how would we achieve that?

Also, do you have any plan to bring back the shortcode generator? This would definitely be useful for dynamic elements like that.

Thank you!

Hi There,

You can create a breadcrumb shortcode ([breadcrumbs]) by adding this custom code to the functions.php file locates in your child theme:

    // Shortcode to add breadcrumbs to Header Builder
function my_breadcrumbs( ) {
        $breadcrumbs_on = x_get_option( 'x_breadcrumb_display' );
        if ( $breadcrumbs_on == '1' ) :
                $breadcrumbs = x_breadcrumbs();
        endif;
        return $breadcrumbs;
}
add_shortcode( 'breadcrumbs', 'my_breadcrumbs');

If you wish to use the shortcode generator, then go to your X > Settings and enable Show Legacy Shortcode Generator. Then create a draft post and insert the shortcode into the editor, then copy them and paste to your widget.

Hope it helps :slight_smile:

Hello Thai,

Thank you for the provided code.

Unfortunately it's not rendering anything.

We're using this for our product category template like that:
<?php echo do_shortcode('[breadcrumbs]'); ?>

I have slightly modified the function because we have not enabled the breadcrumbs general settings.

function nh_breadcrumbs() {
    $breadcrumbs = x_breadcrumbs();
    return $breadcrumbs;
}
add_shortcode( 'breadcrumbs', 'nh_breadcrumbs');

I have added a link to our website in the secure note.

Waiting for your feedback.

Thanks again for your help.

Hey @thisisbbc,

Sorry for the confusion. Please remove the code provided because there already is a Breadcrumb element available in our builders. For more details about the Breadcrumb element, please see https://theme.co/apex/forum/t/elements-breadcrumb/10221

The Breadcrumb element is also a V2 or a non-Classic element. Only Classic elements are available in the Legacy Shortcode Generator. And, the generator can only be used in the WordPress editor and not in the builder.

If you intend to display a breadcrumb in the header only for a specific term page or product category archive page, I'd recommend that you create a header for it then use the custom assignment filter cs_match_header_assignment. Here's an usage example https://michaelbourne.ca/assign-pro-header-search-results-page/

You can see the complete WordPress conditional tags you can use at https://codex.wordpress.org/Conditional_Tags

If you really need a shortcode, the supported method is to use the Global Blocks feature. See https://theme.co/apex/forum/t/global-blocks/24723. Create a block and add a Breadcrumb element to the block. You can then use the block's shortcode to display elsewhere in your site.

Thanks.

Hey Christian,

Thank you for pointing out the global block function, looks like it's what I need.

While the suggestion to use a custom assignment for a header is great too, I'm afraid it wouldn't offer the level of flexibility we're looking for (i.e: pulling the product category image as the default background for the header section).

Creating a custom shortcode seems rather easy and straightforward with the global block so I'm really happy this feature exist. I didn't really have a use for it until now but I feel like I'm gonna be using it more often.

By any chance, would you be able to give an ETA for the next major update? I'm impatiently waiting for the layout module to come out so that we can edit the shop page and other archives with Pro.

Thank you!

Hi @thisisbbc,

Yes, global block has a lot to offer especially for modular design. About the next update, we're not sure about so I can't tell any ETA.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.