[Support request] Add javascript to header.php

Home Forums Support Add javascript to header.php

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1036205
    Hugo

    Hi.
    I have to add a javascript code to a header.php

    How i do that? Thanks a lot.

    This is the code:

    <script async type=”text/javascript” src=”https://smart-home.com.co/JavaScript/LeadControlAPIV2.js”></script&gt;
    <script language=”javascript” type=”text/javascript”>

    document.addEventListener(‘click’, function (e) {
    if (e.target && e.target.id == ‘idBtnEnviar’) {
    submitLeadForm(e, “hA/lvw9cX/9c0GBwnEspO8CP4sbd1qsSGftT-e/zcSQANn2BkZKWeATeX8v3sgbB”);
    }
    });

    function submitLeadForm(element, projectId) {

    var elementButton = document.getElementById(element.target.id);
    var form = elementButton.form;

    const SH = new SmartHomeAPIV2(projectId);
    var formData = SH.getFormData(form.elements);

    const nameFields = [‘form-field-name’];
    const emailFields = [‘form-field-email’];
    const mobileNumberFields = [‘form-field-field_1’];
    const commentsFields = [[‘form-field-field_2′,’¿Qué te gustaría saber del proyecto?’],[‘form-field-message’,’Mensaje’]];

    var data = {
    firstName: SH.getFieldValue(formData, nameFields),
    lastName: ”,
    email: SH.getFieldValue(formData, emailFields),
    mobile_number: SH.getFieldValue(formData,mobileNumberFields),
    phone_number:”,
    comment: SH.getMultipleFieldValue(formData, commentsFields),
    origin: window.location.href

    };
    if (data.firstName == “” || data.email == “” || data.mobile_number == “”) {
    customAlert(“Verifique los datos”);
    return;
    }
    SH.postLeadData(data, ”);
    }

    </script>

    #1036212
    David
    Staff
    Customer Support

    Hi there,

    you can add it using the Hook Element:

    https://docs.generatepress.com/article/hooks-element-overview/

    the WP_head hook is the one you need

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.