Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #191083

    Peter B
    Participant

    Hi,
    I am trying to just have breadcrumbs working in the Woocommerce pages of the X Theme – Ethos but not on other pages in the site. I have disabled the theme breadcrumbs in Customizer but can’t get normal woocommerce breadcrumbs working just in shop. I have Yoast WordPress SEO and can get breadcrumbs in header or footer by adding the required code:
    <?php if ( function_exists(‘yoast_breadcrumb’) ) {
    yoast_breadcrumb(‘<p id=”breadcrumbs”>’,'</p>’);
    } ?>

    But can’t work out how to get this code to only work in shop pages. It is mainly the home page that I don’t want breadcrumbs on – http://imagedecor.com.au/fdev/test-home but I really don’t need them for anything but the shop. I also need the breadcrumbs to show the path including the category not just a link straight back to home.

    Hope you can help, this is driving me crazy!

    cheers
    peter

    #191593

    Paul R
    Moderator

    Hi Peter,

    Thanks for writing in!

    You can change your code to this.

    <?php if ( function_exists('yoast_breadcrumb') && x_is_shop()) {
           yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    } ?>
    

    Hope that helps.

    #192223

    Peter B
    Participant

    Hi, thanks. I am getting a syntax error on the line

    yoast_breadcrumb(‘<p id=”breadcrumbs”>’,'</p>’);

    Here is the error I am getting:

    Parse error: syntax error, unexpected T_STRING in /home/imagedec/public_html/dev/wp-content/themes/x-child-ethos/framework/views/ethos/wp-header.php on line 28

    Would there be any reason for that?

    thanks
    Peter

    #192231

    Peter B
    Participant

    Hi, I fixed the syntax error by replacing the single quotes around the p tags as the ones that I copied from here were curly and when I replaced them they became straight and worked.

    But when I put this code into the wp-header.php file in this path: VIEWS/ETHOS/WP-HEADER.PHP in my child theme I am not getting any breadcrumbs. Should I be putting it somewhere else?

    thanks
    peter

    #192605

    Zeshan
    Member

    Hi Peter,

    I tested the function in my local setup and it doesn’t output anything. We’d love to help you with this, but regretfully, we cannot provide support for third party plugins or scripts as our support policy in the sidebar states due to the fact that there is simply no way to account for all of the potential variables at play when using another developer’s plugin or script. Because of this, any questions you have regarding setup, integration, or troubleshooting any piece of functionality that is not native to X will need to be directed to the original developer.

    Thank you for your understanding.

    #193104

    Peter B
    Participant

    Hi,

    I understand. My problem is that I have 3 options with breadcrumbs.
    1. X theme breadcrumbs turned on in Customiser
    2. Woocommerce default breadcrumbs (which just aren’t working)
    3. Yoast SEO breadcrumbs (which I am putting the code you gave me in the wp-header.php file but not working as you know).

    The easiest thing to do is to use the X theme breadcrumbs in Customiser but I only want breadcrumbs in the shop pages. Is that possible. Or alternatively, does the X theme turn off the woocommerce breadcrumbs and if so is there a way of turning them on?

    I was hoping to use the Yoast SEO breadcrumbs for a number of reasons but mainly as they give the full path back from the product back through the category and back to home rather than just product back to home. I will continue to try to get this to work as I have had it working previously but if you could respond to the couple of questions above I would appreciate it.

    Thanks
    Peter

    #193709

    Rad
    Moderator

    Hi Peter,

    Maybe I could give you a little boost so you know where you can start 🙂

    You can simply add this code at your child theme’s functions.php,

    if ( ! function_exists( 'x_breadcrumbs' ) ) :
      function x_breadcrumbs() {
    
      //Your breadcrumbs code here
    
      }
    endif;

    This will override your default breadcrumbs, and even override the display options at your customizer. You will simply going to add your own breadcrumbs code inside.

    For example,

    if ( ! function_exists( 'x_breadcrumbs' ) ) :
      function x_breadcrumbs() {
    
          yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    
      }
    endif;

    The thing is, we really can’t help you find out why 3rd party codes won’t work. You should contact their respective authors and plug their working code within the given code from us 🙂

    You can also wrap your code with condition, like if you wish to display breadcrumbs on certain pages only 🙂

    Like this,

    if ( ! function_exists( 'x_breadcrumbs' ) ) :
      function x_breadcrumbs() {
    
          if( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
            
               yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    
          }
    
      }
    endif;

    Hope this helps.

    Thanks!

    #193876

    Peter B
    Participant

    Hi, thanks heaps for helping. Both options you offered worked sort of 🙂

    The first option means I have breadcrumbs on every page in the site which I was hoping to avoid. The second option where you select pages to show the breadcrumbs works but only on the product category page like: http://imagedecor.com.au/dev/product-category/abstract/

    But when I click through to that product the breadcrumbs are gone. I’m guessing I need to understand better which pages to add in the code: if( x_is_shop() || x_is_product_category() || x_is_product_tag() )
    as I am hoping to get it to start at the product categories and keep going while visitors are browsing the products in the store to help with navigation.

    If I turn the breadcrumbs on site wide can I put some code in that turns it off particular pages (like can I turn off the breadcrumbs on a specific page like: http://imagedecor.com.au/dev/test-home/ )

    Sorry to be a pain but there are some pages that just don’t need the breadcrumbs and some that do!

    Hope you can help.
    peter

    #194602

    Kory
    Keymaster

    Hey Peter,

    No problem at all! I think the best course of action here would be to do as you said—enable breadcrumbs site wide but turn them off on particular pages. To do so, simply enable your breadcrumbs in the Customizer and then add the following code to your functions.php file in your child theme:

    function remove_specific_breadcrumbs() {
    
      $ids = array( 138, 'my-page', 'My Page' );
    
      if ( is_page( $ids ) || is_single( $ids ) ) {
        return 0;
      } else {
        return 1;
      }
    
    }
    
    add_filter( 'pre_option_x_breadcrumb_display', 'remove_specific_breadcrumbs' );

    How this code works is you will add either an ID, slug, or title to a page or post in the $ids array (make sure each one is separated by a comma as the example is). You can use any of these forms of data, just pick which one works easiest for you. Next, the information in this array is passed into the if statement and will check if the page or post being viewed matches one of the pieces of data you provided. If the statement is true, it will remove your breadcrumbs, otherwise it will simply leave them on like normal.

    You can of course alter the if statement to include whatever conditional you would like. WordPress has plenty of them available for you to choose from, and we even have some X specific conditionals you can use yourself if you’d like, which can be found in /framework/functions/global/conditionals.php in the theme. You could alter this to be more “global” in scope so that it keeps the breadcrumbs from appearing on any page or post at all:

    function remove_specific_breadcrumbs() {
    
      if ( is_page() || is_single() ) {
        return 0;
      } else {
        return 1;
      }
    
    }
    
    add_filter( 'pre_option_x_breadcrumb_display', 'remove_specific_breadcrumbs' );

    As you can see, this is done by removing the $ids variable and not passing it into the two conditionals in the if statement. If you want to add another conditional, you can do so by adding another || symbol (as seen between the is_page() and is_single() conditionals). This means “or” in PHP, so what we’re saying is essentially, “if the entry I’m looking at is a page or a post…” and then you alter your data from there. The return values given in each example are simply passed into the x_option_x_breadcrumb_display filter, which changes the option value on the fly, but not in your database.

    This should give you exactly what you’re looking for! Have a great day! 🙂