Add ACF custom fields to content analysis

Since version 4.6 of SEOPress, all Advanced Custom Fields are now added automatically to the content analysis 🎉.

By default, the content analysis feature doesn’t include fields created with the Advanced Custom Fields plugin.

We don’t want to analyse fields that doesn’t make sense.

Good news, we have a hook to add your own custom fields to our content analysis.

To do that, simply copy and paste this snippet to your functions.php file of your child theme:

Replace “my-custom-field” with the name of your custom field. To find its name, go to Custom Fields, choose a field groups, and edit a field to see its name.

Advanced Custom Fields, field name

If you have several custom fields, you can do something like this:

function sp_content_analysis_content($content, $id) { 
	//$content = default WP editor 
	//$id = current post ID 
	//Example to add your custom field to content analysis 
	$cf = get_post_meta($id, 'my-custom-field', true);
        $cf2 = get_post_meta($id, 'my-custom-field2', true); 
	$content = $content.$cf.$cf2; 
	return $content;
add_filter('seopress_content_analysis_content', 'sp_content_analysis_content', 10, 2);

You can also use an array / foreach to manage dozens of custom fields more efficiently.

Example with ACF repeater fields

That’s it! These fields will now be analyzed when you edit / create a new content.

Last modified: May 27, 2021