-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yoast-provided filter for disabling Yoast breadcrumb schema output not working properly #16711
Comments
I can confirm this bug. After applying the filter, it outputs Breadcrumbs schema leftovers, it seems at every page (which isn't unexpected). |
The filter seems to work correctly: it removes the breadcrumb piece from the schema output. What it does not do is remove the reference to the breadcrumb. That is what you're seeing. This can be removed by, for example, this snippet: add_filter( 'wpseo_schema_webpage', 'remove_breadcrumb_schema_ref', 10, 1);
function remove_breadcrumb_schema_ref( $piece ){
unset( $piece['breadcrumb'] );
return $piece;
} This might need some tweaking with different sites, but that's the nature of filters; Don't blindly copy-paste. Closing this issue as not applicable. |
I have a similar problem trying to conditionally remove graph pieces. Is there an alternative to checking if plugins are loaded? ==================================== if ( is_plugin_active( YOAST_PLUGIN ) ) {
add_action( 'plugins_loaded', function () {
// This works...you can add an Event schema
// ...and you can check the global $post type to do conditional tests**
if ( ! class_exists( 'WPSEO_Schema_Event' ) ) {
require_once PLYO_SCHEMA_EXTENDER_PATH . '/classes/WPSEO_Schema_Event.php';
}
$pieces[] = new WPSEO_Schema_Event( $context, 'Event' );
// But you CANNOT remove graph pieces inside the function - this fails!
add_filter( 'wpseo_schema_graph_pieces', 'remove_breadcrumbs_from_schema', 11, 2 );
add_filter( 'wpseo_schema_webpage', 'remove_breadcrumb_schema_ref', 10, 1);
} ); // is_plugin_active end
// BUT...if you try to remove pieces out here, it WORKS
// ...but global $post is NOT available yet, so yo can't do conditional checks on the post**
add_filter( 'wpseo_schema_graph_pieces', 'remove_breadcrumbs_from_schema', 11, 2 );
add_filter( 'wpseo_schema_webpage', 'remove_breadcrumb_schema_ref', 10, 1);
/**
* Remove Yoast Pieces from the graph
*
* @param array $pieces graph pieces to output.
* @param \WPSEO_Schema_Context $context Yoast object with context variables.
*/
function remove_breadcrumbs_from_schema ( $pieces, $context ) {
return \array_filter( $pieces, function( $piece ) {
return ! $piece instanceof \Yoast\WP\SEO\Generators\Schema\Breadcrumb;
} );
}
function remove_breadcrumb_schema_ref ( $pieces ) {
unset( $pieces['breadcrumb'] );
return $pieces;
} So, you can't remove pieces after plugins are loaded and the plugins_loaded event has fired? |
@Djennez If someone wants to disable Yoast breadcrumbs completely, why not remove the reference as well? What's the point of a reference to nothing? |
Please give us a description of what happened.
Since Yoast 15.8, breadcrumb schema output is included on all pages, even if you’re not using the Yoast breadcrumb function – and we’re not.
There’s an example from Yoast here of how to exclude just the breadcrumb schema output:
https://developer.yoast.com/features/schema/api/#disable-schema
The filter provided is:
When implemented in functions.php this removes some of the breadcrumb schema, but there is still a trace left e.g.
,"breadcrumb":{"@id":"https://www.example.com/folder/page/#breadcrumb"},
This exists in the Yoast generated schema, it’s not being created by anything else, and as it’s incorrect, it also triggers an error in Google’s Structured Data Testing Tool.
Please describe what you expected to happen and why.
I expected this to exclude the breadcrumb graph pieces from showing up in the schema output as that filter's comments state "Removes the breadcrumb graph pieces from the schema collector".
How can we reproduce this behavior?
Technical info
Used versions
The text was updated successfully, but these errors were encountered: