Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccurtin/250ed945ebcbcb558fd8 to your computer and use it in GitHub Desktop.
Save ccurtin/250ed945ebcbcb558fd8 to your computer and use it in GitHub Desktop.
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
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment