Add A Shortcode To An HTML Module [RESOLVED]

I’m attempting to add a shortcode I built inside WPBakery to a form. However, everything I’ve found online and tried as failed. Is there no possible way to do this? Thanks in advance.

Yo could populate de field dynamically using this hook and the do_shortcode() function:

@EliasGomez Thank you. I think that only works if you create another form and populate a different form with that form’s information.

What I’m trying to do is take a shortcode I created in WPBakery or Visual Composer, for most of us oldies. Take that and place it in an HTML module. See attached.

Shortcode I’m attempting to place

Module on the form side

Thanks again for taking the time. I truly appreciate it.

Yes I understood you. As I can see, the HTML field accepts shortcodes. I just placed a [embed] shortcode and it works.

Also, testing the filter I linked, I see that the HTML field does not have a parameter, so the hook should be other. I removed the shortcode from the HTML field, created a shortcode with JetEngine, and created a snippet with gform_pre_render_{form_id} hook and it works.

Captura de pantalla 2021-08-04 a las 10.21.16

Hope this helps.

By the way, the shortcode from JetEngine works also works if placed on the form field settings. But if you need more flexibility you can use the hook, for instance to retrieve the shortcode from anywhere else.

1 Like

Hey Elias! Thank you man for taking the time to do this. I actually ended up using that page after I looked at it and went a bit deeper.

add_filter( 'gform_pre_render', 'encore_do_shortcode_gform_html', 10, 2 );

function do_shortcode_gform_html( &$item, $key ) {
  if ( is_string( $item ) ) {
    $item = do_shortcode( $item );
       } else {
    $item['html'] = do_shortcode( $item['html'] );

function encore_do_shortcode_gform_html( $form, $ajax ) {

  $form['html'] = do_shortcode( $form['html'] );
  array_walk_recursive( $form['fields'], 'do_shortcode_gform_html' );

  return $form;

Thanks again for leading me to a solution. I truly appreciate it!


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.