Including a shortcode into html field
-
Hi there,
I have followed this thread to get a shortcode to be displayed in the html field: https://www.ads-software.com/support/topic/using-shortcode-in-forminator/#post-12881666
I haven’t been able to get it to work yet.
At the moment I have added ‘forminator-render-shotycodes.php’ into my ‘mu-plugins’ folder with the following code:
<?php // Render shortcode on HTML fields add_filter( 'forminator_replace_variables', 'do_shortcode' ); // Include shortcode output to hidden field add_filter( 'forminator_custom_form_submit_field_data', function( $field_data_array ){ $form = array( 'field' => 'html-1', // Form html field 'shortcode' => '[wp24_domaincheck]' // Shortcode to be rendered ); foreach( $field_data_array as &$field_single ){ if( $field_single['name'] === $form['field'] ){ $field_single['value'] = strip_tags( do_shortcode( $form['shortcode'] ) ); } } return $field_data_array; });
I tried to include the following code of @ckgrafico, but I am not sure how. It doesn’t work for me atm.
function forminator_callback($html) { // WordPress does not like to use shortcodes in html attributes preg_match_all('|(="\[.*\])(.*)(\[\/.*\])|U', $html, $matches); $codes = $matches[0]; if (!$codes) { return do_shortcode($html); } foreach ($codes as $code) { $html = str_replace($code, do_shortcode($code), $html); } return do_shortcode($html); } add_filter( 'forminator_render_fields_markup', 'forminator_callback' );
Hoping you can help me with this issue.
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Including a shortcode into html field’ is closed to new replies.