ACF Custom Image Fields

#205408
  • Resolved Matt Rogers
    Rank Math free

    My posts contain an ACF image field inside an ACF Flexible Content layout.

    item_contents > item_image

    How do I get my sitemap to read the item_image fields from inside the item_contents flexible layout? If i enter item_image into the Custom Image Fields, the sitemap still shows 0 images per post.

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

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay.

    Rank Math comes with the ACF module that allows Rank Math to process all of the content in ACF for the purposes of content analysis & optimization. Could you please confirm if you have already enabled the ACF Module in Rank Math > Dashboard?

    ACF Flexible Content Layout

    Please note that some options are only available when you enable the Advanced Mode in Rank Math. If it’s not showing, you must have chosen to use the Easy Mode. Please follow the steps in this link to switch to Advanced Mode:
    https://rankmath.com/kb/advanced-mode/

    You can also refer to the following article for more details: https://rankmath.com/kb/advanced-custom-fields/

    If the issue still persists, please also share your sitemap and the affected URL to check further. You can add them in the sensitive data section

    I hope that helps.

    Thank you, and please don’t hesitate to contact us anytime if you need further assistance with anything else.

    Hi Reinelle.

    Yes, I have enabled ACF in Rank Math.

    My issue is that our ACF image fields are inside an ACF Repeater field. The Repeater field is called “item_contents” and the image fields are name “item_image”.

    How do I get Rank Math SEO to read my “item_image” fields within each post type? i.e. what do I need to put in the box under Rank Math -> Sitemap Settings -> Artists (this is a custom post type) -> Image Custom Fields. If I just enter “item_image”, my sitemap still returns 0 images for any Artists.

    Thanks,
    Matt

    Hello,

    Thanks for getting back.

    Can you please make sure that you have enabled the Include Images from ACF Fields option in WP Dashboard > Rank Math > Sitemap Settings?

    If the option is enabled and the images are still not being included then we might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    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,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    The “Include images from ACF Fields” option does not show on my interface.

    I have shared a temporary login with you via sensitive data.

    Thanks,
    Matt

    Hello,

    Thanks for getting back.

    Sorry for the confusion, the Include Images from ACF Fields is only available in the PRO version.

    I checked with the devs and the images will only be added in the sitemap by entering the field name in the Image Custom Fields Box when you’re using an actual image field. It will not work with the flexible content fields.

    However, you can modify and use this filter to add images manually to your sitemap: https://rankmath.com/kb/filters-hooks-api-developer/#remove-change-images

    You can follow this guide to know how to use filters and hooks: https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php

    Hope this helps. Let us know if you need any further assistance.

    /**
    * Filter images to be included for the post in XML sitemap.
    *
    * @param array $images Array of image items.
    * @param int $post_id ID of the post.
    */
    add_filter( ‘rank_math/sitemap/urlimages’, function( $images, $post_id ){
    return $images;
    }, 10, 2);

    What do you need to return in $images? I have tried returning the image url and also the image src (https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/), however none of the above has an affect on the sitemap.

    Below is an example of my code:

    add_filter( ‘rank_math/sitemap/urlimages’, function( $images, $post_id ) {

    // error_log($post_id);
    if (have_rows(‘item_content’, $post_id)) :
    while( have_rows(‘item_content’, $post_id) ) : the_row();
    $image = get_sub_field(‘item_image’);
    $images[] = $image[‘url’];
    endwhile;
    endif;

    return $images;

    }, 10, 2);

    Thanks,
    Matt

    Hello,

    Thanks for getting back to us.

    We need information such as the title and source of the image to be added to the sitemap. Here’s a complete example we have of adding those images from the WP Bakery Page Builder:

    
    add_filter( 'rank_math/sitemap/urlimages', function( $images, $id ){
        if ( empty( $images ) ) {
            $post = get_post( $id );
            if ( $post && strpos( $post->post_content, '[vc_row' ) !== false ) {
                preg_match_all( '/(?:image|images|ids|include)\=\"([^\"]+)\"/', $post->post_content, $matches );
                foreach ( $matches[1] as $m ) {
                    $ids = explode( ',', $m );
                    foreach ( $ids as $id ) {
                        if ( (int) $id ) {
                            $images[] = array(
                                'src' => wp_get_attachment_url( $id ),
                                'title' => get_the_title( $id ),
                            );
                        }
                    }
                }
            }
        }
    
        return $images;
    }, 10, 2 );
    

    Hope this helps clarify all the needs of this filter.

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

The ticket ‘ACF Custom Image Fields’ is closed to new replies.