Hi there,
I am trying to: Add a breadcrumb shortcode to my theme using Yoast SEO and a custom shortcode that I've inserted into my header parent layout.
I've enabled breadcrumbs in yoast and created a custom breadcrumb shortcode.
But when I insert my shortcode into my layout it's just coming up with square brackets... this makes me think there's something wrong with my shortcode.
If you take a look at hidden link - you'll see a white band above the blue header. This is incorrect and seems to be inserted by Yoast after I turned on their breadcrumb functionality.
Then below the header you see my shortcode.
It seems like Yoast is inserting the breadcrumb (that says home on every page - without actually showing the breadcrumb trail.)
See my attached screengrabs of:
- how the header should look (no home breadcrumb above the header)
- my custom shortcode
- functions file
- my layout in edit mode
Thanks in advance for your support.
Guy
Hi, did you test your shortcode without Types and Layouts enabled? I don't quite understand your setup, but I don't think it's coded correctly:
add_shortcode('yoast_breadcrumb', 'wildheart_breadcrumb');
This indicates that you are creating a new shortcode, 'yoast_breadcrumb'. When this shortcode is rendered, WP will look for the function 'wildheart_breadcrumb' and execute that function. However, I do not see this function anywhere in the code you have provided. Am I missing something?
More info about the shortcode API here:
https://codex.wordpress.org/Shortcode_API
if ( function exists('yoast_breadcrumb')) {
yoast_breadcrumb('<p id="breadcrumb">', '</p>');
}
I'm not sure what this is supposed to do, or how it is supposed to relate to the shortcode. Here's an example of the shortcode implementation I use:
// custom shortcode to display results count based on View ID passed in as shortcode attribute
add_shortcode( 'ts_view_num_results', 'ts_view_num_results_func');
function ts_view_num_results_func($atts)
{
$view_id = intval($atts['viewid']);
$results = get_view_query_results( $view_id );
return count($results);
}
Then I use the shortcode like this:
[ts_view_num_results viewid="123"]
Thanks Christian,
I spent another hour on this but couldn't get it working. I've never created a shortcode before so been muddling through it.
I've found a plugin that add the Yoast breadcrumb shortcode to our site.
I wanted to avoid using another plugin and also don't like the markup that this shortcode generates. But I need to keep moving forward.