Archived topic
Delete or change schema
8 replies · Started by Roman on January 16, 2018
Hi!
Is it posible to delete or change schema, for example "itemtype='http://schema.org/CreativeWork'"?
I have installed Code Snippet plugin and added snippet with code from another topic:
add_filter( 'generate_article_schema', 'example_function_name' );
function example_function_name()
{
return '';
}
But it's didn't work. Did I do something wrong?
Hi Roman,
Currently it's not possible to remove the markup completely.
We do have plans on changing how attributes are added to elements, which will allow you to remove everything from microdata to classes and IDs.
Can I replace or remove only values of itemtype?
I found your code in another topic, which is looks like what i've been searching for:
add_filter( 'generate_body_itemtype', 'tu_custom_body_itemtype' );
function tu_custom_body_itemtype( $type ) {
if ( is_page( array( 'about', 'about-us' ) ) ) {
return 'AboutPage';
} elseif ( is_page( array( 'contact', 'contact-us' ) ) ) {
return 'ContactPage';
} elseif ( is_search() ) {
return 'SearchResultsPage';
} elseif ( is_front_page() ) {
return 'WebPage';
} elseif (is_single() ) {
return 'Article';
} else {
return 'WebPage';
}
}
I've tried to add this (with 'generate_article_schema' instead 'generate_body_itemtype') and previous code in Code Snippet plugin and directly to new plugin file. It still doesn't work. Do I need to add only this code or somthing else? Or these filters not working now?
Absolutely, that should work.
You can see the filter here: https://github.com/tomusborne/generatepress/blob/2.0.2/inc/markup.php#L47
So if you switch out the filter name and change CreativeWork to another valid itemtype, it should update.
Can you check this code on your site?
I simplified the code as much as possible, to prevent any errors:
add_filter( 'generate_article_schema', 'tu_custom_body_itemtype' );
function tu_custom_body_itemtype( $type ) {
return 'WebPage';
}
Still have "CreativeWork" on all pages. :(
Instead of generate_article_schema, try generate_article_itemtype.
It works with generate_article_itemtype. Thanks!
You're welcome :)
Edit - wrong thread.