Skip to content

Instantly share code, notes, and snippets.

@koen12344
Created January 31, 2024 11:10
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 koen12344/49a75a79e9a430d4b4d6e0c60b322e5f to your computer and use it in GitHub Desktop.
Save koen12344/49a75a79e9a430d4b4d6e0c60b322e5f to your computer and use it in GitHub Desktop.
Add a custom taxonomy to the Post to Google My Business plugin
<?php
/*
* Add a custom taxonomy variable to the Post to Google My Business plugin
*/
function pgmb_add_custom_taxonomy($variables, $parent_post_id){
//Replace name_of_the_taxonomy with the name of your taxonomy
$terms = get_the_terms( $parent_post_id, 'name_of_the_taxonomy' );
if($terms && !is_wp_error($terms) && !empty($terms)){
//Replace my_custom_taxonomy with a variable name of your choosing (make sure it doesn't start with any HTML url encoding characters from https://www.w3schools.com/tags/ref_urlencode.ASP to avoid conflicts)
$variables['%my_custom_taxonomy%'] = $terms[0]->name;
}
return $variables;
}
add_filter('mbp_placeholder_variables', 'pgmb_add_custom_taxonomy', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment