• Resolved ArtGoddess

    (@artgoddess)


    Hello,

    After this suggestion:

    https://wordpress.org/support/topic/breadcrumbs-in-twenty-twenty-one/

    I have located a plugin for the breadcrumbs.

    I need to place a snippet of php code that outputs a shortcode.

    My question is: in which file do I have to place the php code to show the breadcrumbs in all pages, posts and custom post types, exactly in the same position?

    I was thinking between the header and the title of the page, post or CPT. Just below the site logo.

    Many thanks!

    • This topic was modified 7 months, 3 weeks ago by ArtGoddess.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Felipe Santos

    (@foosantos)

    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);
    
    Thread Starter ArtGoddess

    (@artgoddess)

    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.

    Thread Starter ArtGoddess

    (@artgoddess)

    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.

    Thread Starter ArtGoddess

    (@artgoddess)

    Ok, location is at the very bottom of: template-parts/header/site-nav.php of my twenty-twenty child theme file. Thank you.

    Moderator Felipe Santos

    (@foosantos)

    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.

    Thread Starter ArtGoddess

    (@artgoddess)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Breadcrumbs php location in theme files, where?’ is closed to new replies.