• Resolved tapper101

    (@tapper101)


    Hi,

    This is probably super easy, but I can’t find any information that shows exactly how to do this.

    So the site I’m working on has news article (custom post type) that are posted regularly, now for SEO purposes it’s important that these are marked up as NewsArticle specifically, and not Blog. We also intend to create other types of custom posts, so it would be great if we could change the schema on a per post type basis to be more accurate with our meta data.

    I’m aware that there are some filters I can use, but I’m not entirely sure how they are used. Specifically to change a particular post type instead of all posts globally.

    Any tips?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    It’s possible to change the itemtype, but it would require you to add the extra necessary markup to your articles for those types to be valid. Have you considered using a JSON+LD plugin? Yoast has this built-in now, and there are other options out there as well.

    That way you can turn off the default microdata in the theme, and set up more advanced schema for your site using JSON+LD.

    Let me know if that’s something you want to do. Otherwise, I can share some example filters for changing the itemtype in GP ??

    Thread Starter tapper101

    (@tapper101)

    Hi Tom,

    I’m very impressed by your support here. ??

    I’m using All in One SEO at the moment, but yes I do hear good things about Yoast. AIOSEO should come with JSON+LD as well, as I just read, but it doesn’t seem to work great for custom posts.

    It’s actually empty for my news article type. Just a pair of brackets:

    <script type="application/ld+json" class="aioseop-schema">{}</script>

    But that’s a AIOSEO issue, I shouldn’t bother you with that.

    I think for now, I’d like to just change the markup for the articles myself, so if you have some example filters you want to share I would greatly appreciate it. Heck, might just be a good way to learn more about structuring Schema markup.

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    @tapper101

    All in One SEO Pack dev here.

    AIOSEOP does come with JSON+LD, though we don’t (yet) add it to custom post types by default. (Although that’s on the way!)
    You can add it to custom post types using the code example here: https://semperplugins.com/documentation/enabling-schema-for-custom-post-types-and-custom-taxonomies/

    Thread Starter tapper101

    (@tapper101)

    Glad to hear you’re implementing it in the future, Michael (@hallsofmontezuma). Another reason to stick with AIOSEOP. And thanks a lot for the help – I’ll give it a go right away!

    @edge22 (Tom), if you have a code snippet readily available or if it’s not too much work, I’d still like to see your example filters. Otherwise, fixing it through AIOSEOP will probably do.

    Thanks!

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    @tapper101

    ??Awesome!

    I’ll duck out of this thread now, but feel free to reach out to us if you have any AIOSEOP-specific questions.
    If you’d like to provide input on the development of this or any other issues, we welcome all user input right on Github. For instance, here are the existing schema.org issues: https://github.com/semperfiwebdesign/all-in-one-seo-pack/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+schema
    or you’re welcome to open your own for something new.

    Have a great day!

    Theme Author Tom

    (@edge22)

    Give this a shot:

    add_filter( 'generate_body_microdata', function( $data ) {
        if ( 'your-type' === get_post_type() ) {
            $data = 'NewsArticle';
        }
    
        return $data;
    } );

    Let me know if that does the trick or not ??

    Thread Starter tapper101

    (@tapper101)

    Sort of worked, it seems to add attributes at the end of the body tag. So literally

    <body class="...classes..." newsarticle>

    Not what was intended I guess, but changing it to this works.

    add_filter( 'generate_body_microdata', function( $data ) {
        if ( 'nyhet_post' === get_post_type() ) {
            $data = 'itemscope itemprop="https://schema.org/NewsArticle"';
        }
    
        return $data;
    } );

    Thanks ???? I’ll probably just use AIOSEOP’s json+ld in the end, Michael’s solution worked quite well.

    Theme Author Tom

    (@edge22)

    Ah sorry – my mistake! Your code is perfect.

    Using JSON+LD is definitely the future of schema ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Change itemtype schema.org/Blog to schema.org/Article (or other) for posts?’ is closed to new replies.