Rank Math with ACF image

#831973
  • Resolved Mark
    Rank Math free

    Hi there, I am using your plugin for a client of me. We are very happy with your plugin. We just discovered a strange issue. We have filled in all the ALT tags of the images, but still the score give an error (issue is 10.2 Focus Keyword in Image Alt Attributes in your do). If I watch the source code of the page all alt tags are filled with the focuskeyword. For example, if you look at the source code of this case. If I add an image in a WYSIWYG that works perfect. But we have a couple of ACF fields which might be the problem. We also enabled the ACF function of Rank Math and have the correct settings on the Rank Math settings page.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for reaching out to us. I understand that you are facing an issue with the Rank Math plugin regarding the ALT tags of images when using ACF fields.

    Based on the information provided, it seems that the ALT tags filled in for the images are not being recognized by Rank Math, even though they are correctly set in the source code. This could be related to the way ACF fields are being used for images.

    To ensure that Rank Math recognizes the ALT tags from ACF fields, you can follow these steps:

    1. Update the Focus Keyword Using ACF Field: You can add a code snippet to your theme’s rank-math.php file to update the focus keyword using the ACF field. Here is the code snippet you can use:
    function update_focus_keywords() {
        $posts = get_posts(
            array(
                'posts_per_page' => -1,
                'post_type'      => 'post', // replace post with the name of your post type.
            )
        );
        foreach ( $posts as $p ) {
            // Replace 'article_topic' with your ACF field name.
            if ( ! get_post_meta( $p->ID, 'rank_math_focus_keyword', true ) && function_exists( 'get_field' ) && ( null !== get_field( 'article_topic', $p->ID ) ) ) {
                update_post_meta( $p->ID, 'rank_math_focus_keyword', strtolower( get_field( 'article_topic', $p->ID ) ) );
            }
        }
    }
    add_action( 'init', 'update_focus_keywords' );
    1. Add the Code Snippet: Update the focus keyword using the ACF field by adding the provided code snippet to your theme’s rank-math.php file. Make sure to replace 'article_topic' with your actual ACF field name.

    Add the code snippet

    After adding and updating the code snippet, make sure to save the changes and check if Rank Math recognizes the ALT tags from ACF fields correctly.

    If you need further assistance or have any other questions, feel free to ask. Thank you for using Rank Math!

    Best regards.

    Sources:
    Score 100/100 With Rank Math Post Tests » Rank Math
    Is There a Way to Use ACF for Focus Keywords? » Rank Math
    Analyzing Your Site’s SEO with Rank Math’s SEO Analysis Tool

    This is an automated reply from Rank Math Support Bot. If you need further assistance, please reply to this topic and a human support agent will reply to you shortly.

    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 ‘Rank Math with ACF image’ is closed to new replies.