Comments (3)
https://wordpress.org/support/topic/structured-data-through-multiple-bound-callbacks-in-filter/
from wordpress-seo.
Hi @controvi, sorry for the delay in my response.
The schema pieces collected via the wpseo_schema_graph_pieces
filter are then filtered by a filter_graph_pieces_to_generate
method which ensures that there is a piece per identifier; if the identifier is not explicitly set, it's created from the class name, as you can see here.
In your snippet I suppose that the CustomGraphData
objects don't have different identifiers, so they are in turn added to the ['customgraphdata']
key, with the second one overwriting the first and the third one overwriting the second:
foreach ( $graph_pieces as $piece ) {
$identifier = \strtolower( \str_replace( 'Yoast\WP\SEO\Generators\Schema\\', '', \get_class( $piece ) ) );
if ( isset( $piece->identifier ) ) {
$identifier = $piece->identifier;
}
/* ... */
$pieces_to_generate[ $identifier ] = $piece;
}
To fix that, you can either set different a different $identifier
property value for each one of the objects, or use different classes.
I hope this helps!
from wordpress-seo.
Hey,
No worries about the late answer.
I found a workaround that seems to work just as well but just makes it 1 call to generated it all.
I do wanted to dive a little deeper into that if I may.
Reason for it is that I don't really understand why this is the way it works.
Whenever I load in a piece to the pieces array, there doesn't have to be a check of what does or doesn't have to be loaded.
As far as I tested, default wordpress behavior doesn't do this either.
Another thing that is weird is that when looking at the api documentation about this, it doesn't tell me to use an $identifier anywhere. Even when looking it up on google and searching for a week, I never found any reference to it. (Not saying I perfectly search the web thought. Can have overlooked something somewhere.)
Maybe it would be good to add something to the documentation about this.
I am trying to add custom graph data to the pieces array for multiple blocks but currently just concat the json through 1 class that eventually loads it all in at once.
Thought still dynamic it is more code than I would have wished.
Finally, just to be sure I understand the code.
I need to add a property "identifier" to the class object that is set in the pieces array.
That identifier will be used to keep all pieces separate and eventually loaded correctly, right?
Again thanks for the reply.
Hope that the docs can be updated as well for future reference.
If there is already mention of this in the docs somewhere I would love to have the link to it.
Especially for future reference when people have the same issue and reach this support ticket through the WordPress forums.
Regards
from wordpress-seo.
Related Issues (20)
- Remove unused translation script data
- Missing pagination page numbers in blog page breadcrumbs HOT 1
- RSS feeds cause fatal error with missing/invalid user HOT 1
- Option to Paste on the description fields are not showing on the right-click menu HOT 9
- Compatibility issue with Easy Digital Downloads Software Licensing since v20.4 HOT 5
- Add integration test to date archive builder
- Elementor FAQ/How-to Block Add HOT 1
- Category Slugs Become Case-Sensitive When "Show the Categories Prefix in the Slug" is Unchecked HOT 1
- [UI-Library] Refactoring Notification component to use the new Toaster element
- Slow to edit product category meta titles or descriptions HOT 1
- Allow the usage of multiple FAQ blocks in a page HOT 6
- Class 'wp-block-yoast-faq-block' and 'wp-block-yoast-how-to-block' missing from the FAQ block and How-to block on version 22.7 HOT 1
- When indexable creation is disabled, cleanups are being scheduled upon post creation
- When indexable creation is disabled, there's redundant db queries on page load, in the frontend of posts
- [UI-Library] `Notifications` property has wrong content
- Refactor AI Generator notification `Dismiss` button
- Decouple hidden fields for custom post types
- Unable to copy and paste words into Search Appearance Meta Description HOT 1
- Yoast replaces the secondary language post contents with the primary language post contents when using Elementor+WPML HOT 1
- Hello, I have the same problem. Does anyone know how to solve it? I even disabled other plugins, reinstalled WordPress and even installed another version, but the problem was not solved. Please help. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-seo.