How to Use ACF Fields in Schema Generator

#349548
  • Resolved Kawah Buku
    Rank Math free

    In this tutorial https://rankmath.com/kb/how-to-use-acf-fields-in-schema-generator/, you only show to add ACF Field for FAQs. Right now I want to use ACF for my custom field, in our case is the tab for Table of Content (you can refer here: https://kawahbuku.com/titles/bajautopia-tales-of-borneos-sea-nomads/).

    This is the code that I change a few places accordingly:

    add_filter( ‘rank_math/json_ld’, function( $data, $jsonld ) {
    if( ! have_rows(‘table_of_contents’) ) {
    return $data;
    }
    $data[‘faqs’] = [
    ‘@type’ => ‘FAQPage’,
    ];
    while( have_rows(‘table_of_contents’) ) {
    the_row();
    $data[‘faqs’][‘mainEntity’][] = [
    ‘@type’ => ‘Question’,
    ‘name’ => esc_attr( get_sub_field(‘faq_question’) ),
    ‘acceptedAnswer’ => [
    ‘@type’ => ‘Answer’,
    ‘text’ => esc_attr( get_sub_field(‘faq_answer’) ),
    ],
    ];
    }
    return $data;
    }, 10, 2 );

    —-

    I change the acf-repeater-faq with table_of_contents, but how about:

    ‘@type’ => ‘FAQPage’, — what should I put here?

    ‘name’ => esc_attr( get_sub_field(‘faq_question’) ), — what should I replace faq_question

    ‘text’ => esc_attr( get_sub_field(‘faq_answer’) ), — same here

    Since in our ACF setup for Table of Content, we only have field name, that is table_of_content and we dont have any other element. How to custom your code here?

    Regards,
    Iskandar

Viewing 1 replies (of 1 total)
  • Hello,

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

    There’s no Schema markup for the table of contents so if you would like to use that data for any other type you need to explicitly state what is the type that you are trying to add that information to.

    The value “FAQPage” is the type of Schema and you need to change that to the type that you want to have on the page.

    ​​​​​​​Hope this helps clarify your doubts.

    Don’t hesitate to get in touch if you have any other questions.

    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 1 replies (of 1 total)

The ticket ‘How to Use ACF Fields in Schema Generator’ is closed to new replies.