• styven

    (@styven)


    I would like not to display the text, but to render the shortcode that I insert into my custom field. How can I do this?

    In my exemple it’s the shortcode of HubSpot Form

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Phi Phan

    (@mr2p)

    Hi @styven, The block does not support running the shortcode in the current version, so you have to write some custom code to run it as follows:

    add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) {
      $field_name = $attributes['fieldName'] ?? '';
    
      if ( 'hubspot_form' === $field_name ) {
        $block_content = do_shortcode('[hubspot type="form" portal="143926370" id="bd447015-acd9-411f-97dc-1a1cb939f53d"]');
      }
    
      return $block_content;
    }, 10, 4);

    Put that code in your theme or plugin and input hubspot_form in the fieldname.

    The block will support running shortcode in the fieldname in the next version. It is now in the beta version and will be released in a few days. I will let you know in this thread when it’s ready.

    Phi.

    • This reply was modified 10 months ago by Phi Phan.
    Thread Starter styven

    (@styven)

    Hi, thanks a lot ! It’s still not working, we have an error :

    window.hsFormsOnReady = window.hsFormsOnReady || []; window.hsFormsOnReady.push(()=>{ hbspt.forms.create({ portalId: 143926370, formId: ??bd447015-acd9-411f-97dc-1a1cb939f53d??, target: ??#hbspt-form-1706025828000-7250269067??, region: ??eu1??, })});
    Plugin Author Phi Phan

    (@mr2p)

    @styven Can I ask why you need to use the MFB to display the shortcode in the first place? Does it work if you put it in the core/shortcode block? It looks like your shortcode output some script that is not allowed to display in the block. If you still want to display it in MFB, you should allow those special tags to be displayed in the frontend. You could do as follows:

    add_filter( 'meta_field_block_kses_allowed_html', function ( $allowed_html_tags ) {
      $allowed_html_tags['script'] = [
        'src'  => true,
        'type' => true,
     ];
    
      return $allowed_html_tags;
    });
    Thread Starter styven

    (@styven)

    My aim is to add a custom field in a regular page with my hubspot shortcode inside and the template have to show it in my page where I want.

    I have another problem with ponctuation :

    window.hsFormsOnReady.push(()=>{ instead of window.hsFormsOnReady.push(()=>{
    Plugin Author Phi Phan

    (@mr2p)

    @styven Why don’t you use the core/shortcode block to display it? Does it work if you put it in the core/shortcode block? If the output of your shortcode contains other disallowed tags and attributes, you have to allow them using my previous snippet.

    Thread Starter styven

    (@styven)

    If I use the shortcode block, it will be always the same HubSpot form. Imagine 10 ebooks, I will put in custom field the HubSpot Shortcode and your MFB block display the shortcode in the page.

    • This reply was modified 10 months ago by styven.
    Plugin Author Phi Phan

    (@mr2p)

    You should try to decode the output of the shortcode to make the arrow character is not encoded. Mayb use the html_entity_decode function.

    Thread Starter styven

    (@styven)

    I will wait until your release, it’s too complex for me, sorry. Thank you so much for your help!

    • This reply was modified 10 months ago by styven.
    Plugin Author Phi Phan

    (@mr2p)

    @styven, I have released a new version that supports displaying shortcode as a dynamic field. To display it, you need to set the field type to dynamic and input the shortcode in the field name.

    Best,
    Phi.

    Thread Starter styven

    (@styven)

    Hi!

    Thanks a lot for your work, it’s amazing ??

    Unfortunately, we have the same problem as yesterday, some ponctuation in javascript are changed and it’s not working ?? :

    window.hsFormsOnReady.push(()=>{ hbspt.forms.create({

    instead of

    window.hsFormsOnReady.push(()=>{ hbspt.forms.create({
    • This reply was modified 10 months ago by styven.
    Plugin Author Phi Phan

    (@mr2p)

    @styven This issue is not related to MFB. It is the way WordPress outputs the content. You can do a little hack to bypass it as follows:

    function hubspot_content_filter( $content ) {
      if ( has_shortcode( $content, 'hubspot' ) ) {
        $content = str_replace('>','>',$content );
      }
      return $content;
    }
    add_filter( 'the_content', 'hubspot_content_filter' );

    You could learn more about it in this thread.

    Phi.

    Thread Starter styven

    (@styven)

    Thank you, I’m stopping here, it’s not working sorry. Thank you for your time and have a good day.

    Plugin Author Phi Phan

    (@mr2p)

    Ah, I found an issue in my previous snippet. If you still want one more try, you just remove the check for shortcode exists and I think it will work. The code as follows:

    function hubspot_content_filter( $content ) {
      return str_replace('>','>',$content );
    }
    add_filter( 'the_content', 'hubspot_content_filter' );
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to show form not text’ is closed to new replies.