Created
January 31, 2024 11:10
-
-
Save koen12344/49a75a79e9a430d4b4d6e0c60b322e5f to your computer and use it in GitHub Desktop.
Add a custom taxonomy to the Post to Google My Business plugin
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 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