Processes Groundhogg merge tags (e.g. {first_name}, {email}) in a string and returns the result with all recognised tags replaced by their values for the given contact. Use this any time you need to personalise content outside of the normal email pipeline — such as in a custom SMS message, webhook payload, or dynamic page heading.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | The string containing merge tags to process. |
$contact_id | int|Contact | The contact whose data will be used. Accepts a contact ID or Contact object. |
$context | string | The output context. Accepts 'html' (default) or 'plain'. |
Return value
string — The content string with all recognised merge tags replaced.
Usage
$message = 'Hello {first_name}, your account email is {email}.';
$personalised = \Groundhogg\do_replacements( $message, $contact );
// Result: "Hello Jane, your account email is jane@example.com."
echo $personalised;
Example
Here’s a pseudo code example for a hypothetical SMS integration.
add_action( 'groundhogg/contact/tag_applied', 'my_plugin_send_sms_on_tag', 10, 2 );
/**
* Send a personalised SMS when a specific tag is applied.
*
* @param \Groundhogg\Contact $contact
* @param int $tag_id
*
* @return void
*/
function my_plugin_send_sms_on_tag( $contact, $tag_id ) {
if ( $tag_id !== MY_PLUGIN_WELCOME_TAG_ID ) {
return;
}
$template = get_option( 'my_plugin_sms_template', 'Hi {first_name}! Welcome to {business_name}.' );
$message = \Groundhogg\do_replacements( $template, $contact );
my_plugin_send_sms( $contact->get_mobile_number(), $message );
}
Was this helpful?
Let us know if this document answered your question. That’s the only way we can improve.
