Filter: mbp_placeholder_variables
The mbp_placeholder_variables filter can be used to alter or add variables to be replaced with their corresponding value in a GMB post. It has two arguments, $variables and $parent_post_id.
Samples
Add a variable
This will replace%custom_variable% with Custom value in the text of your post
function add_custom_variable($variables, $parent_post_id){
$variables['%custom_variable%'] = 'Custom value';
return $variables;
}
add_filter('mbp_placeholder_variables', 'add_custom_variable', 10, 2);
Add a field from ACF
The filter can be used to get custom fields from the Advanced Custom Fields pluginfunction add_custom_variable($variables, $parent_post_id){
//Return early if the get_field() function from ACF doesnt exist (e.g. when the plugin is deactivated)
if(!function_exists('get_field')){ return $variables; }
$variables['%my_acf_field%'] = (string)get_field('field_name', $parent_post_id);
return $variables;
}
add_filter('mbp_placeholder_variables', 'add_custom_variable', 10, 2);
Remove a variable
Removes the%post_permalink% variable so it will no longer be replaced
function remove_variable($variables){
unset($variables['%post_permalink%']);
return $variables;
}
add_filter('mbp_placeholder_variables', 'remove_variable');