Home › Forums › ACF PRO › ACF PRO fields inside of Yoast – meta title and meta Description › Reply To: ACF PRO fields inside of Yoast – meta title and meta Description
I got this it to work thru paying for custom programming for it AND then fixed it myself to have it work correctly.
Use following code inside of Yoast Meta Title and meta Description fields inside of pages/posts:
%%VariableName%%
I have only tested this with TEXT field in ACF PRO.
Below is what goes into Functions.php
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
$seo_variables = get_fields('options');
if ( function_exists('get_fields') ){
if( $seo_variables ) {
$seo_variables_array = array();
foreach( $seo_variables as $name => $value ):
$seo_variables_array[$name] = $value;
endforeach;
}
}
function ss_get_all_values($var1){
global $seo_variables_array;
// echo($seo_variables_array[$var1]);
return $seo_variables_array[$var1];
}
function ss_register_custom_yoast_variables() {
$seo_variables = get_fields('options');
if ( function_exists('get_fields') ) {
if( $seo_variables ) {
$seo_variables_array = array();
foreach( $seo_variables as $name => $value ):
wpseo_register_var_replacement( $name, 'ss_get_all_values', 'advanced');
endforeach;
}
}
}
// Add action
add_action('wpseo_register_extra_replacements', 'ss_register_custom_yoast_variables');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.