Advanced Custom Fields and Yoast SEO keyword analysis

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.

Read More

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'] );
        }

Related posts

2 comments

  1. 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?

  2. Ho, @hyperdrive – we wrestled with the exact same scenario and need and wrapped our solution / approach in a plugin:

    http://wordpress.org/plugins/ns-seo-custom-fields/

    You can use the standard custom field name(s) from the edit interface or ACF’s “Field Name” value, and there’s a screenshot to show where to find those exact values:

    http://wordpress.org/plugins/ns-seo-custom-fields/screenshots/

    We just released it and it works for us so let us know if it works well for you too. You can probably scavenge what you need from the plugin itself, or modify it to fit your exact needs… or check out the pro version that does even more including unlimited field support.

Comments are closed.