Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-seopress/732e9b57c6dcc33bf4c04af31f4b2ca9 to your computer and use it in GitHub Desktop.
Save wp-seopress/732e9b57c6dcc33bf4c04af31f4b2ca9 to your computer and use it in GitHub Desktop.
Create a dynamic variable from Advanced Custom Fields options page for SEOPress metadata
function sp_titles_template_variables_array($array) {
$array[] = '%%_acf_options_my_field_name%%';
$array[] = '%%_acf_options_my_field_name_2%%';
return $array;
}
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array');
function sp_titles_template_replace_array($array) {
$array[] = esc_attr(wp_strip_all_tags(get_field('my_field_name', 'option')));
$array[] = esc_attr(wp_strip_all_tags(get_field('my_field_name_2', 'option')));
return $array;
}
add_filter('seopress_titles_template_replace_array', 'sp_titles_template_replace_array');
function sp_get_dynamic_variables($array){
$array['%%_acf_options_my_field_name%%'] = __('My field name from ACF options page', 'my-text-domain');
$array['%%_acf_options_my_field_name_2%%'] = __('My field name 2 from ACF options page', 'my-text-domain');
return $array;
}
add_filter('seopress_get_dynamic_variables', 'sp_get_dynamic_variables');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment