[Resolved] Delete or change schema

Home Forums Support [Resolved] Delete or change schema

Home Forums Support Delete or change schema

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #472956
    Roman

    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?

    #473419
    Tom
    Lead Developer
    Lead Developer

    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.

    #473462
    Roman

    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?

    #473818
    Tom
    Lead Developer
    Lead Developer

    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.

    #474710
    Roman

    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. ๐Ÿ™

    #475382
    Tom
    Lead Developer
    Lead Developer

    Instead of generate_article_schema, try generate_article_itemtype.

    #480876
    Roman

    It works with generate_article_itemtype. Thanks!

    #480922
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

    #1813090
    robchanoi

    Edit – wrong thread.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.