Add ACF values to Schema

#102635
  • Resolved Tiago Faia
    Rank Math free

    Hi,

    Congrats for the great plugin!

    I have a woocommerce store and I need to add EAN and brand to schema. I know you have an option to add the brand, but it’s not working with my brand attribute for some reason (it’s not showing in schema).

    So, to fix both, brand and EAN, I’ve created 2 custom fields on my product pages and I would like to use them on Schema. Is this possible? How can I do it? 🙂

    Many thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Yes, you would need to code a little bit (or hire a freelancer) but it is possible.

    You can modify any Schema with this filter:

    /**
     * Collect data to output in JSON-LD.
     *
     * @param array  $unsigned An array of data to output in json-ld.
     * @param JsonLD $unsigned JsonLD instance.
     */
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	return [];
    }, 99, 2);

    And you can get any ACF value with:
    get_field('field_name',$id); // Being $id the post id

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Thanks for your help.

    Will that add to the schema or replace it all?

    How would I add the brand for example? Like this?

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	$brand = get_field('marca_customfield',$id);
    	return [
    		'brand': "$brand"
    	];
    }, 99, 2);

    Thanks

    • This reply was modified 4 years, 1 month ago by Tiago Faia.
    Michael Davis
    Rank Math pro

    Hello,

    This doesn’t replace schema, it adds schema to existing schema.

    Your filter would be something as shown below:

    
    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	$brand = get_field('marca_customfield',$id);
            $data[brand] = $brand;
    	return [];
    }, 99, 2);
    

    Hope this helps you. Thank you.

    Tiago Faia
    Rank Math free

    Hi,
    Thanks but when I do that, my Product Schema disappears completely.

    Alberto
    Rank Math business

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping 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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Add ACF values to Schema’ is closed to new replies.