- This topic has 7 replies, 2 voices, and was last updated 2 years, 6 months ago by
David.
-
AuthorPosts
-
March 8, 2023 at 6:10 am #2559981
Brand
All my WooCommerce single product article elements have this HTML schema markup:
itemtype="itemtype="https://schema.org/CreativeWork""
I expect this is to be a conflict with the Yoast plugin. I’d like to keep all the schema markup added by GP such as the navigation elements, but not the schema markup for articles, as I want this to be handled by the Yoast plugin.
I’ve tried:
add_filter( 'generate_article_itemtype', 'itemtype' ); function itemtype( $type ) { return ''; }
Which just returns this in the HTML:
itemtype="itemtype="https://schema.org/""
I also tried:
add_filter( 'generate_schema_type', '__return_false' );
Which removes all the markup completely.
If it helps, I’d like to do something like this:
add_filter( 'generate_schema_type', 'itemtype' ); function itemtype( $element ) { if( is_product() && $element == 'article' ) { return false; } }
However, the parameter in
generate_schema_type
holds the valuemicrodata
. Can’t find a use for this to build some logic that disables the schema markup for the article element.If anyone stumbling upon this knows how to disable the schema markup on WooCommerce single product articles through Yoast, that would also suffice. But I’d prefer to just disable it in GP.
March 8, 2023 at 7:58 am #2560272David
StaffCustomer SupportHi there,
try this:
add_filter( 'generate_article_microdata',function( $data ) { if( is_product() ) { return false; } return $data; } );
For more detail you can find the filter here:
https://github.com/tomusborne/generatepress/blob/4895a2e7595bb809075b375201fd735112f41570/inc/theme-functions.php#L500March 8, 2023 at 9:30 am #2560418Brand
Hi David, thanks for the quick reply.
Unfortunately this doesn’t seem to make any change.
The output is still the same:itemtype="itemtype="https://schema.org/CreativeWork""
.I disabled a lot of the installed plugins, including Yoast, but the issue persisted.
I finally managed to find the issue, which is caused by a function inthemes/generatepress/inc/class-html-attributes.php
.public function woocommerce_content( $attributes ) { if ( is_singular() ) { $attributes['id'] = 'post-' . get_the_ID(); $attributes['class'] = esc_attr( implode( ' ', get_post_class( '', get_the_ID() ) ) ); if ( 'microdata' === generate_get_schema_type() ) { $type = apply_filters( 'generate_article_itemtype', 'CreativeWork' ); $attributes['itemtype'] = sprintf( 'itemtype="https://schema.org/%s"', $type ); $attributes['itemscope'] = true; } } else { $attributes['class'] = 'woocommerce-archive-wrapper'; } return $attributes; }
If I modify
$attributes['itemtype']
so it looks like this:if ( 'microdata' === generate_get_schema_type() ) { $type = apply_filters( 'generate_article_itemtype', 'CreativeWork' ); $attributes['itemtype'] = 'https://schema.org/' . $type; $attributes['itemscope'] = true; }
And using this filter:
add_filter( 'generate_article_itemtype', function( $type ){ return 'WebPage'; });
It gives me the correct output in the HTML:
itemtype="https://schema.org/WebPage" itemscope
Is there any way I can make these changes without having to go into the core files? And is this an error with the plugin itself, or perhaps a conflict with another plugin?
March 8, 2023 at 10:06 am #2560444David
StaffCustomer SupportHmmm…. you should not need to modify the theme functions for this to work:
add_filter( 'generate_article_itemtype', function($type){ if( is_product() ) { return 'webPage'; } },99 );
I added the priority just in case but i didn’t need it on my test site.
March 9, 2023 at 1:11 am #2561046Brand
That filter works for changing the itemtype, but the markup itself was still messed up. The filter would give this output:
itemtype="itemtype="https://schema.org/WebPage""
The
woocommerce_content()
function was returning the wrong output on WooCommerce single product pages. I suspect this might be an issue with the GeneratePress theme itself.$attributes['itemtype'] = sprintf( 'itemtype="https://schema.org/%s"', $type );
to
$attributes['itemtype'] = 'https://schema.org/' . $type;
fixed it for me.March 9, 2023 at 2:00 am #2561117David
StaffCustomer SupportHmmm… that was a bug we fixed here:
https://github.com/tomusborne/generatepress/issues/457Is the theme up to date ?
March 9, 2023 at 2:05 am #2561131Brand
It’s not. But I’ll look into that ASAP 🙂 thank you for your time David
March 9, 2023 at 3:31 am #2561239David
StaffCustomer SupportYou’re welcome. Let us know how you get on.
-
AuthorPosts
- You must be logged in to reply to this topic.