Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Created September 10, 2018 14:50
Show Gist options
  • Select an option

  • Save NickDeckerDevs/83e8d52f98dc567a74bbaf027c46193c to your computer and use it in GitHub Desktop.

Select an option

Save NickDeckerDevs/83e8d52f98dc567a74bbaf027c46193c to your computer and use it in GitHub Desktop.
shortcode to use hubspot embed in wordpress sites to make sure JS doesn't move your form below the footer
function get_hubspot_form_embed( $atts ) {
// to use this embed code follow this:
// [hubspot_form form_id='{{ hubspot form id }}']
// [hubspot_form form_id='ca34cd96-d5b2-4dc4-b412-f7fc6f73abc4']
// uses a random class to keep this form targeted
$a = shortcode_atts( array(
'form_id' => '',
), $atts );
$rand = 'form-class-' . substr(md5(microtime()),rand(0,26),9);
$form = '<div class="' . $rand . ' insert-form hbspt-form"></div>';
$form .= '<!--[if lte IE 8]><script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script><![endif]-->';
$form .= '<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>';
$form .= '<script> hbspt.forms.create({portalId: "135870", formId: "' . $atts[ 'form_id' ] . '",css:"", target: ".' . $rand . '" });';
$form .= '</script>';
return $form;
// old version
// to use this embed code follow this:
// [hubspot_form form_id='{{ hubspot form id }}']
// [hubspot_form form_id='ca34cd96-d5b2-4dc4-b412-f7fc6f73abc4']
// $a = shortcode_atts( array(
// 'form_id' => '',
// ), $atts );
// $form .= '<!--[if lte IE 8]><script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script><![endif]-->';
// $form .= '<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>';
// $form .= '<script> hbspt.forms.create({portalId: "135870", formId: "' . $atts[ 'form_id' ] . '",css:"" });';
// $form .= '</script>';
// return $form;
}
add_shortcode( 'hubspot_form', 'get_hubspot_form_embed' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment