Change the terms agreement checkbox text

📅 Published on

📝 Last updated

Documentation

»

Code Samples

»

Change the terms agreement checkbox text

Changes the terms agreement checkbox text in Groundhogg forms.

<?php

/**
 * Modify the terms and conditions field label to include a hyperlink.
 *
 * This function customizes the label for the "terms_agreement" checkbox field,
 * inserting a clickable link to the terms and conditions page.
 *
 * @param string $label The default field label.
 * @param string $field The field type.
 * @return string The modified field label with a hyperlink.
 */
function custom_terms_and_conditions_label( $label, $field ) {
    // Check if the field is the terms and conditions agreement checkbox.
    if ( $field === 'terms_agreement' ) {
        // Define the URL of the terms and conditions page.
        $url = esc_url( 'https://example.com/terms/' );

        // Modify the label to include a hyperlink to the terms and conditions.
        $label = sprintf(
            __( 'I agree to <a href="%s" target="_blank">terms and conditions</a> of %s.', 'groundhogg' ),
            $url,
            get_bloginfo()
        );
    }

    return $label;
}

// Hook the custom function into the Groundhogg default field label filter.
add_filter( 'groundhogg/default_field_label', 'custom_terms_and_conditions_label', 10, 2 );

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.