Error using breadcrumbs shortcode

Hi guys,
I have a site, https://hilltopmontessori.com, which has upwards of 30 pages using a breadcrumbs shortcode that was working fine until a recent update. Now we are getting some strange behavior I hope you can help with.

First of all, I put the following code in my child theme’s functions.php:
add_shortcode(‘breadcrumbs’, ‘x_breadcrumbs_display’);
function x_breadcrumbs_display ($atts) {
ob_start();
x_breadcrumbs();
return ob_get_clean();
}

It works just fine when the pages are rendered. The breadcrumbs show up nicely. The problem comes when I try to edit a page. If I go to Pages, then click the main page title from a list of pages, I get the following error:

Fatal error: Uncaught Error: Call to undefined function x_breadcrumbs() in /home/hilltop8/public_html/wp-content/themes/x-child/functions.php:57 Stack trace: #0 /home/hilltop8/public_html/wp-includes/shortcodes.php(319): x_breadcrumbs_display('', '', 'breadcrumbs') #1 [internal function]: do_shortcode_tag(Array) #2 /home/hilltop8/public_html/wp-includes/shortcodes.php(197): preg_replace_callback('/\\[(\\[?)(breadc...', 'do_shortcode_ta...', '<p>[breadcrumbs...') #3 /home/hilltop8/public_html/wp-content/plugins/cornerstone/includes/elements/classic/text/shortcode.php(15): do_shortcode('<p>[breadcrumbs...') #4 /home/hilltop8/public_html/wp-content/plugins/cornerstone/includes/classes/classic/elements/class-element-wrapper.php(158): include('/home/hilltop8/...') #5 /home/hilltop8/public_html/wp-includes/shortcodes.php(319): Cornerstone_Element_Wrapper->shortcode_output('class="x-text" ', '[breadcrumbs]', 'cs_text') #6 [internal function]: do_shortcode_tag(Array) #7 /home/hilltop8/public_html/wp-includes/shortcodes.php(197): in /home/hilltop8/public_html/wp-content/themes/x-child/functions.php on line 57

If I hover over the page name and click Edit in Cornerstone, I am able to edit the page just fine. However, when I exit Cornerstone, I get the same Fatal Error as above.

Additionally, when editing the page in Cornerstone, the block or code that should display the [breadcrumbs] shortcode is invisible. No matter how I try to hover or click in that area, I cannot locate it. Can you advise here if there is a way to see it?

Because of the volume of pages, I don’t want to have to go and edit each one to use the newer Breadcrumbs element if I can avoid it.

Thanks so much,
Cindy

Hello Cindy,

Thanks for writing in!

I have tested the code in my local testing server with the latest X and Cornerstone.
I could not replicate any error.

Live page view:

Cornerstone Preview:

Would you mind providing us the url of your site with login credentials so we can take a closer look? To do this, you can create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Thank you.

Hi Cindy,

You can try adding a conditional statement, please change the code to this.

add_shortcode('breadcrumbs', 'x_breadcrumbs_display');
function x_breadcrumbs_display ($atts) {
   if (  function_exists( 'x_breadcrumbs' ) )  {
       ob_start();	
       x_breadcrumbs();	
       return ob_get_clean();
    }
    return null;
}

Hope this helps

Thank you - that does work to eliminate the errors we were receiving!

Can you help me shed any light on why the [breadcrumbs] shortcode does not show up when I edit the page in Cornerstone? It should be in the right column of the first row. It clearly must still be there, as when you view the page it shows up. I cannot figure it out. I’d really appreciate any insight you might have into that. If it matters, I think the header section in each page was created from a template.

Thanks!

Hello Cindy,

I also updated the code in my local installation using @Paul.r’s code. I can see the shortcode that is working when I edit the page in Cornerstone.

I am using a text element by the way. Are you using raw content element?

Hope this helps. Kindly let us know.

Hi guys - I see the element now. It looks like it showed back up once I wrapped the code in an error check. All seems well now. Thanks for your help.

We are delighted to assist you with this.

Cheers!

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