Last active
March 23, 2023 02:33
-
-
Save ccurtin/250ed945ebcbcb558fd8 to your computer and use it in GitHub Desktop.
ACF searchable custom fields for Wordpress for YOAST SEO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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