Bulk edit schema

#89361
  • Resolved Dean
    Rank Math free

    I need to change the schema from article to new article for all news category posts while leaving the others as the standard article.

    Is there a way to do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    Thank you for getting in touch with us.

    You can customize and use the following filter to change your schema. For example add an if to check if post belongs to the news category then return the schema type

    
    /**
     * Filter to change the schema data.
     * Replace $schema_type with schema name like article, review, etc.
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( "rank_math/snippet/rich_snippet_article_entity", function( $entity ) {
     return $entity;
    });
    

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hi Michael

    Can you please expand on your answer a little, please?

    I am trying this for fields under the Organisation type, under Event.

    I think I’m close, but as it’s all nested fields, I’m not entirely sure if I’m 1) calling the right filter (should it be “event” or “organizer” or something else?), and 2) how to then properly target the fields that need to be updated – see this attempt (items wrapped in ?? indicate my uncertainty):

    add_filter( "rank_math/snippet/rich_snippet_??ORGANIZER/EVENT??_entity", "adz_event_schema_org_url" );
    function adz_event_schema_org_url($entity) {
    	$entity['??@type??'] = "Organization";
    	$entity['??name??'] = "Event 2 Event";
    	$entity['??URL??']  = "https://event2event.co.uk";
    	
    	return $entity;
    }

    Hope that makes sense.

    Thanks

    • This reply was modified 3 years, 6 months ago by Adam Helman.

    Hello,

    You can try the following:

    
    /**
     * Filter to change the schema data.
     * Replace $schema_type with schema name like article, review, etc.
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( "rank_math/snippet/rich_snippet_article_entity", function( $entity ) {
     global $post;
         // filter for only a specific category
         if(get_category() == "your_category_name_here"){
     $entity['@type']= 'NewsArticle';
     return $entity;
         }
    
     return $entity;
    });
    

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hi – thanks for the reply.

    I fully understand your snippet re an Article – but what I’m asking is what changes in the filter if it’s an Event?

    Does “rank_math/snippet/rich_snippet_article_entity” become “rank_math/snippet/rich_snippet_event_entity”?

    Or (because I’m dealing with an Organizer within Event) is it “rank_math/snippet/rich_snippet_event_entity” or “rank_math/snippet/rich_snippet_organizer_entity”?

    🙂

    Dean
    Rank Math free

    Thanks for that. I take it this gets placed in the functions.php file, presumably in a child theme?

    Hello Adam,

    The filter I provided is for an article schema. To modify an event schema type, you will need to modify the same to: rank_math/snippet/rich_snippet_event_entity


    @Dean
    do you wish to mar this as resolved?

    Hope this helps you. Thank you.

    ​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

The ticket ‘Bulk edit schema’ is closed to new replies.