Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Last active April 24, 2024 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/0ac789256a214a7c622fd960e876c9dd to your computer and use it in GitHub Desktop.
Save zackpyle/0ac789256a214a7c622fd960e876c9dd to your computer and use it in GitHub Desktop.
Fluent Forms - Use custom shortcode attr and FF SmartCode to pass dynamic Submit Button text
<?php
// Register Fluent Forms SmartCode
add_filter('fluentform/editor_shortcodes', function ($smartCodes) {
$smartCodes[0]['shortcodes']['{submit_button_text}'] = 'Dynamic Submit Button Text';
return $smartCodes;
});
// Use text from submit_button_text attribute on the form's shortcode
add_filter('fluentform/editor_shortcode_callback_submit_button_text', function ($value, $form) {
$dynamicText = get_query_var('submit_button_text');
// Set a fallback if nothing is passed
return $dynamicText ?: 'Schedule Demonstration';
}, 10, 2);
// Store the custom submit button text so it can be used in the SmartCode callback
add_filter('fluentform/shortcode_defaults', function($defaults, $atts) {
if(isset($atts['submit_button_text'])) {
set_query_var('submit_button_text', sanitize_text_field($atts['submit_button_text']));
}
return $defaults;
}, 10, 2);
@zackpyle
Copy link
Author

Use like this: [fluentform id="1" submit_button_text="Request Info"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment