Hi @artgoddess,
I recommend you never add it directly to a theme file and instead use hooks to do what you want.
A good way would be with the the_title filter. I got an example for you from ChatGPT (but I would only recommend you add it if you know how the code works to keep your site reliable and safe):
function add_breadcrumb_before_title($title, $id = null) {
if (is_page() && $id) { // Adjust conditions as needed
$breadcrumb = do_shortcode('[my_shortcode_name]');
return $breadcrumb . ' ' . $title;
}
return $title;
}
add_filter('the_title', 'add_breadcrumb_before_title', 10, 2);
Thank you @foosantos, this solution has a strange effect, it mixes the menu and the breadcrumbs.
In fact, I am using a child theme, and I have copied only this php snippet of code into my header.php child theme file:
<div id="content" class="site-content">
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
if ( !is_front_page() && function_exists('saswp_render_breadcrumbs_html') ) {
echo do_shortcode( '[saswp-breadcrumbs]' );
} ?>
But the behaviour is really strange, as I have stated in other thread.
https://wordpress.org/support/topic/breadcrumbs-twentig-with-schema-structured-data-for-wp-amp-plugin/
Thank you for any assistance you may provide.
I have tried with other breadcrumbs plugins. The result is the same. This issue is related to the Twenty Twenty-One theme or the Twentig plugin. Any assistance would be really appreciated. Thank you.
Ok, location is at the very bottom of: template-parts/header/site-nav.php of my twenty-twenty child theme file. Thank you.
Hi @artgoddess, thank you for sharing how you did it!
Small note that if there are updates on this file of the parent theme, you would need to update this manually — that’s the reason that I recommend you to use hooks, as it would still work even after updates.
Thank you, @foosantos, I’m afraid I’m not a developer, and I don’t know how to create the hook for this scenario.
If anybody is open to sharing a correct snippet of code, that would be great. Thanks again.