ccurtin
1/11/2015 - 7:14 AM

ACF searchable custom fields for Wordpress for YOAST SEO

ACF searchable custom fields for Wordpress for YOAST SEO

<?php

add_filter('wpseo_pre_analysis_post_content', 'add_custom_to_yoast');

function add_custom_to_yoast( $content ) {
	global $post;
	$pid = $post->ID;
	$custom = get_post_custom($pid); //gets all custom fields in an arry of the current post/page
	unset($custom['_yoast_wpseo_focuskw']); // Don't count the keyword in the Yoast field!

	foreach( $custom as $key => $value ) {
		if( substr( $key, 0, 1 ) != '_' && substr( $value[0], -1) != '}' && !is_array($value[0]) && !empty($value[0])) {
		  $custom_content .= $value[0] . ' ';
		}
	}
	$content = $content . ' ' . $custom_content;
	return $content;
	remove_filter('wpseo_pre_analysis_post_content', 'add_custom_to_yoast'); // don't let WP execute this twice
}

?>