The problem I’m having is the keyword page analysis tool doesn’t read my custom fields so I am trying to figure out how to run a filter on them.

I found a blog post on Yoast website here here which references this issue and they list the filter wpseo_pre_analysis_post_content, but I am unsure of how to run this on the fields.

I found an action for running a function on the admin edit screen on the ACF website : acf/input/admin_head, but I don’t know how to run the filter on the actions that have been loaded.

EDIT:

I found out the acf plugin actually has this filter built in but doesnt seem to be working.

        // set value
        if( !isset($field['value']) )
        {
            $field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
            $field['value'] = apply_filters('acf/format_value', $field['value'], $post_id, $field);

            apply_filters( 'wpseo_pre_analysis_post_content', $field['value'] );
        }

2 s
2

Looking at the filter:

$post_content = apply_filters( 'wpseo_pre_analysis_post_content', $post->post_content, $post );

it would be a matter of adding your fields content to string being analyzed.

You have to do the get_field() part right, this is untested:

add_filter( 'wpseo_pre_analysis_post_content', 'filter_yoasts_wpse_119879', 10, 2 );

function filter_yoasts_wpse_119879( $content, $post )
{
    $fields = get_field( 'name', $post->ID );
    return $content . $fields;
}

As noted by kaiser in comments, the get_field() function is not reliable. If it is a relatively simple field, it’s better to stick to get_post_meta.

Related: Where do I put the code snippets I found here or somewhere else on the web?

Leave a Reply

Your email address will not be published. Required fields are marked *